uwdata / arquero

Query processing and transformation of array-backed data tables.
https://idl.uw.edu/arquero/
BSD 3-Clause "New" or "Revised" License
1.33k stars 64 forks source link

Aggregates should return null when all values are null #46

Closed peterewills closed 3 years ago

peterewills commented 3 years ago

Right now, if I do op.sum(colName) and all the values of colName are null within a group, the aggregated value for that group is 0.0. IMO it would be more sensible to return null in this case.

Example:

dt = aq.from([{ foo: 1, bar: 1 }, { foo: 1, bar: 3 }, { foo: 2, bar: null }])
dt.groupby('foo').derive({bar: op.sum('bar')})
jheer commented 3 years ago

Thanks @peterewills. I've updated sum to match the behavior of the other non-count aggregate functions. Each returns undefined when invoked over empty or null-only data. Fix will be released shortly in v1.2.3.

peterewills commented 3 years ago

@jheer thanks so much! We're starting to use arquero in our Observable notebooks here at Stitch Fix, and are really appreciating the work you've put into it.