ibis
ibis copied to clipboard
feat(api): allow first/last to work in aggregate (non-window) context
Not sure if it is a bug or i am missing something. Consider the following code snippet: (here i try to generate expression for "first"-based aggregation)
import ibis
tbl= ibis.table(name='A', schema=[('a', 'int32'), ('b', 'string')])
group_by_expression = tbl.aggregate(
[tbl['a'].first().name('BB')],
by=['b']
)
It produces the error:
ibis.common.exceptions.IbisTypeError: argument passes none of the following rules: function_of('table',output_rule=one_of((reduction(), scalar(value(Any(nullable=True),),)),)), reduction(), scalar(value(Any(nullable=True),),), container_of(scalar(value(Any(nullable=True),),),type=<class 'tuple'>), named_literal()
While many other aggregations work good, for example:
import ibis
tbl= ibis.table(name='A', schema=[('a', 'int32'), ('b', 'string')])
group_by_expression = tbl.aggregate(
[tbl['a'].mean().name('BB')],
by=['b']
)
works smoothly.
@evgenygr Thanks for raising the issue. The API you're looking for is probably tbl.a.arbitrary('first'). We will look into making first/last work as you've written them (they only work as window functions right now, mapping to SQL's FIRST_VALUE/LAST_VALUE).
Thanks, Phillip!