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

Invalid column reference on empty table #275

Open
oluckyman opened this issue May 6, 2022 · 2 comments
Open

Invalid column reference on empty table #275

oluckyman opened this issue May 6, 2022 · 2 comments

Comments

@oluckyman
Copy link

Minimal example:

aq.from([]).filter(d => d.key) 
  // or .derive({ test: d => d.key })
  // or .groupby('key')
  // or whatever  

throws: Error: Invalid column reference: "d.key"

Why not return empty table if the input is empty?
My intuition from other libs (d3, lodash, Array.prototype) suggests, that if the input is empty, it should be safe.

d3.filter([], d => d.key) // → []
_.filter([], d => d.key) // → []
[].filter(d => d.key) // → []

If it's by design, what's the arquero way to handle empty inputs?
This seems like an awkward workaround:

arr.length ? aq.from(arr).filter(d => d.key) : aq.from(arr)
@jheer
Copy link
Member

jheer commented May 10, 2022

Thanks for the question. Unlike an empty array (as with the other tools you mention) an empty table in Arquero has a schema describing which columns are defined. Disabling column checks for empty tables would introduce an inconsistency (and might possibly miss genuine errors!) and I'm unsure how much benefit it provides in return -- as soon as a table has one or more rows, the error would of course be raised.

To check if a table has zero rows you can use table.size or table.numRows(). Also feel free to describe your use case in more detail if you still see prevailing benefits for disabling column checks on zero-row tables.

@oluckyman
Copy link
Author

Thanks for the clarification.
My use case is when I have no control on input data for aq.from(input). E.g. when it arrives from fetch or is filtered by brush on a chart.
So, sometimes the input array is empty during the interaction and it blows up the Observable notebook.
I understand, that the workaround to use here is arr.length ? aq.from(arr)... : [].
It just seems awkward in context of otherwise beautiful, declarative and chained flow that this great library provides.
Also in my mental model the schema have no sense for empty data. Whatever manipulation on empty data should produce the empty data. Like in multiplication on zero.
But in arquero it seems like whatever manipulation on empty data will produce error. It's like the empty data is wrong.

Anyway, thanks for your efforts! I'll update my mental model, so you can consider this issue resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants