ibis icon indicating copy to clipboard operation
ibis copied to clipboard

feat(api): allow first/last to work in aggregate (non-window) context

Open evgenygr opened this issue 3 years ago • 2 comments

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 avatar Jun 25 '22 19:06 evgenygr

@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).

cpcloud avatar Jun 28 '22 20:06 cpcloud

Thanks, Phillip!

evgenygr avatar Jun 29 '22 17:06 evgenygr