Skip to content

Commit 490d029

Browse files
authored
feat: align over signature with Polars (#2096)
* feat: align `over` signature with Polars * fix
1 parent 81353a3 commit 490d029

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

narwhals/expr.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,14 +1494,16 @@ def sample(
14941494
)
14951495

14961496
def over(
1497-
self: Self, *keys: str | Iterable[str], _order_by: str | None = None
1497+
self: Self,
1498+
*partition_by: str | Iterable[str],
1499+
_order_by: str | None = None,
14981500
) -> Self:
14991501
"""Compute expressions over the given groups.
15001502
15011503
Arguments:
1502-
keys: Names of columns to compute window expression over.
1503-
Must be names of columns, as opposed to expressions -
1504-
so, this is a bit less flexible than Polars' `Expr.over`.
1504+
partition_by: Names of columns to compute window expression over.
1505+
Must be names of columns, as opposed to expressions -
1506+
so, this is a bit less flexible than Polars' `Expr.over`.
15051507
_order_by: Unused, but this is building up to something.
15061508
15071509
Returns:
@@ -1543,10 +1545,10 @@ def over(
15431545
if _order_by is not None and self._metadata.kind.is_window():
15441546
n_open_windows -= 1
15451547
metadata = ExprMetadata(kind, n_open_windows=n_open_windows)
1546-
flattened = flatten(keys)
1548+
flat_partition_by = flatten(partition_by)
15471549
return self.__class__(
15481550
lambda plx: self._to_compliant_expr(plx).over(
1549-
flattened, kind=self._metadata.kind
1551+
flat_partition_by, kind=self._metadata.kind
15501552
),
15511553
metadata,
15521554
)

tests/expr_and_series/over_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def test_over_single(request: pytest.FixtureRequest, constructor: Constructor) -
4545

4646
result = df.with_columns(c_max=nw.col("c").max().over("a")).sort("i").drop("i")
4747
assert_equal_data(result, expected)
48+
result = df.with_columns(c_max=nw.col("c").max().over(["a"])).sort("i").drop("i")
49+
assert_equal_data(result, expected)
4850

4951

5052
def test_over_multiple(request: pytest.FixtureRequest, constructor: Constructor) -> None:

0 commit comments

Comments
 (0)