Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty lists do not evaluate to true with empty? #3903

Closed
bugabinga opened this issue Aug 6, 2021 · 6 comments · Fixed by #4797
Closed

Empty lists do not evaluate to true with empty? #3903

bugabinga opened this issue Aug 6, 2021 · 6 comments · Fixed by #4797
Assignees
Labels
🐛 bug Something isn't working
Milestone

Comments

@bugabinga
Copy link

Describe the bug

According to the book an empty table piped to empty? should return true.
However it seems to print an empty line instead.

How to reproduce

let colors = []
$colors | empty?

or simply

[] | empty?

Expected behavior

[] | empty? should print true.

Screenshots

No response

Configuration

version | pivot | to md

Column0 Column1
version 0.35.0
build_os windows-x86_64
rust_version rustc 1.54.0 (a178d0322 2021-07-26)
rust_channel stable-x86_64-pc-windows-msvc (default)
cargo_version cargo 1.54.0 (5ae8d74b3 2021-06-22)
pkg_version 0.35.0
build_time 2021-08-04 10:11:37
build_rust_channel release
features clipboard-cli, ctrlc, dataframe, default, rustyline, term, trash, uuid, which, zip
installed_plugins binaryview, chart bar, chart line, fetch, from bson, from sqlite, inc, match, post, ps, query json, s3, selector, start, sys, textview, to bson, to sqlite, tree, xpath

Additional context

Other datatypes work as expected with empty?.

∽
  1 | empty?
false

∽
  "" | empty?
true

∽
  $true | empty?
false

∽
  $false | empty?
false

∽
  0 | empty?
false  () | empty?
true

∽
  $nothing | empty?
true

∽
  0.0 | empty?
false

∽
  0sec | empty?
false

∽
  0..0 | empty?
false

∽
  0b | empty?
false

∽
  [[];[]] | empty?
true

∽
  {} | empty?
true

Notice the table type in particular .
An empty table works: [[];[]].
But an empty list seemingly not: [].

@fdncred fdncred added the 🐛 bug Something isn't working label Aug 6, 2021
@jafriyie1
Copy link
Contributor

@fdncred Is anyone working on this? I'd like to give this a shot if no one is.

@fdncred
Copy link
Collaborator

fdncred commented Aug 10, 2021

Go for it @jafriyie1

@fdncred
Copy link
Collaborator

fdncred commented Aug 17, 2021

Similar issue #3929

@fdncred
Copy link
Collaborator

fdncred commented Aug 17, 2021

@jafriyie1 how's it going on this issue? We've had requests similar to yours here recently.

@jafriyie1
Copy link
Contributor

jafriyie1 commented Aug 18, 2021

@fdncred I stepped away a while from this as I got busy with other things. my apologies. I made a test for the corrected behavior and I am noticing that the issue comes from here empty_code. When I was testing around with this I saw that [] | empty? returns "" instead of true or false.

In addition to this, when we pass in ([] | empty?) | empty? we get the expected boolean. This makes me think that the parser for some reason treats an empty list [] differently than other values. Because of this, I'm wondering how I should go about fixing this. Should we just make an explicit match on []? Or is there a more elegant approach to this?

@fdncred
Copy link
Collaborator

fdncred commented Aug 18, 2021

I'm not sure @jafriyie1. @jntrnr any thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants