From cf9e23dc3c331304bd3ba5defde8f6a3b330811f Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Tue, 19 Mar 2024 09:20:38 +0000 Subject: [PATCH] record "len" as simple aggregation --- narwhals/pandas_like/group_by.py | 4 ++-- narwhals/pandas_like/utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/narwhals/pandas_like/group_by.py b/narwhals/pandas_like/group_by.py index c795fa183..be0495796 100644 --- a/narwhals/pandas_like/group_by.py +++ b/narwhals/pandas_like/group_by.py @@ -102,7 +102,7 @@ def agg_pandas( simple_aggs = [] complex_aggs = [] for expr in exprs: - if is_simple_aggregation(expr, implementation="pandas"): + if is_simple_aggregation(expr): simple_aggs.append(expr) else: complex_aggs.append(expr) @@ -173,7 +173,7 @@ def agg_generic( # noqa: PLR0913 dfs: list[Any] = [] to_remove: list[int] = [] for i, expr in enumerate(exprs): - if is_simple_aggregation(expr, implementation): + if is_simple_aggregation(expr): dfs.append(evaluate_simple_aggregation(expr, grouped)) to_remove.append(i) exprs = [expr for i, expr in enumerate(exprs) if i not in to_remove] diff --git a/narwhals/pandas_like/utils.py b/narwhals/pandas_like/utils.py index 9a349a50d..c916263d8 100644 --- a/narwhals/pandas_like/utils.py +++ b/narwhals/pandas_like/utils.py @@ -232,7 +232,7 @@ def evaluate_simple_aggregation(expr: PandasExpr, grouped: Any) -> Any: Returns naive DataFrame. """ if expr._depth == 0: - return grouped.size()["size"].rename(expr._output_names[0]) + return grouped.size()["size"].rename(expr._output_names[0]) # type: ignore[index] if expr._root_names is None or expr._output_names is None: msg = "Expected expr to have root_names and output_names set, but they are None. Please report a bug." raise AssertionError(msg)