arquero icon indicating copy to clipboard operation
arquero copied to clipboard

arquero op.first_value function issue

Open novotny1akub opened this issue 2 years ago • 0 comments

I am having trouble using op.first_value from arquero. Below is an example that demonstrates the issue. When using, for example, .rollup({sum: op.sum('value')}) instead of .rollup({first_value: op.first_value('value')}), it works fine so I assume this could be a bug in op.first_value because other aggregate functions work fine.

import { aq, op } from '@uwdata/arquero';

aq.table({
    group: ['a', 'a', 'b', 'b', 'b', 'c', 'c'],
    value: [5, 4, 7, 6, 9, 3, 8]
  })
  .groupby('group')
  .rollup({first_value: op.first_value('value')})

novotny1akub avatar Aug 02 '22 14:08 novotny1akub

Hi, first_value is a window function, not an aggregate function, and so only applies in contexts that support ordered windows of values (e.g., derive, but not rollup). The correct behavior is to throw an error when invoking a window function in a non-window context.

The error message, however, should have been much clearer. Your post helped me to find a bug regarding error checking that I've fixed in #288. Thanks!

jheer avatar Aug 12 '22 12:08 jheer

Thanks a lot for the explanation, @jheer.

novotny1akub avatar Aug 12 '22 13:08 novotny1akub