Skip to content

Commit

Permalink
feat(api): support variadic arguments on Table.group_by() (#8546)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCrews authored Mar 5, 2024
1 parent 9a741f7 commit 665bc4f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def schema(self) -> sch.Schema:

def group_by(
self,
by: str | ir.Value | Iterable[str] | Iterable[ir.Value] | None = (),
*by: str | ir.Value | Iterable[str] | Iterable[ir.Value] | None,
**key_exprs: str | ir.Value | Iterable[str] | Iterable[ir.Value],
) -> GroupedTable:
"""Create a grouped table expression.
Expand Down Expand Up @@ -978,9 +978,7 @@ def group_by(
"""
from ibis.expr.types.groupby import GroupedTable

if by is None:
by = ()

by = tuple(v for v in by if v is not None)
groups = bind(self, (by, key_exprs))
return GroupedTable(self, groups)

Expand Down
8 changes: 8 additions & 0 deletions ibis/tests/expr/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,14 @@ def test_group_by_kwargs(table):
assert_equal(expr, expected)


def test_group_by_nargs(table):
t = table
by = ["f", t.h]
e1 = t.group_by(by, z="g").aggregate(t.d.mean().name("foo"))
e2 = t.group_by(*by, z="g").aggregate(t.d.mean().name("foo"))
assert_equal(e1, e2)


def test_compound_aggregate_expr(table):
# See ibis #24
compound_expr = (table["a"].sum() / table["a"].mean()).name("foo")
Expand Down

0 comments on commit 665bc4f

Please sign in to comment.