From 463536e15c2b26da7d9ed7ba5d46fd1c47dd7d5e Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:05:04 +0000 Subject: [PATCH] dont increase depth for alias close #1 --- narwhals/pandas_like/__init__.py | 4 ++-- narwhals/utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/narwhals/pandas_like/__init__.py b/narwhals/pandas_like/__init__.py index 953c56966..a2ff11535 100644 --- a/narwhals/pandas_like/__init__.py +++ b/narwhals/pandas_like/__init__.py @@ -354,13 +354,13 @@ def sample(self, n: int, fraction: float, *, with_replacement: bool) -> ExprT: def alias(self, name: str) -> ExprT: # Define this one manually, so that we can - # override `output_names` + # override `output_names` and not increase depth if self._depth is None: msg = "Unreachable code, please report a bug" raise AssertionError(msg) return Expr( lambda df: [series.alias(name) for series in self.call(df)], - depth=self._depth + 1, + depth=self._depth, function_name=self._function_name, root_names=self._root_names, output_names=[name], diff --git a/narwhals/utils.py b/narwhals/utils.py index 942599dae..e5078109a 100644 --- a/narwhals/utils.py +++ b/narwhals/utils.py @@ -229,7 +229,7 @@ def is_simple_aggregation(expr: Expr) -> bool: return ( expr._function_name is not None # type: ignore[attr-defined] and expr._depth is not None # type: ignore[attr-defined] - and expr._depth <= 2 # type: ignore[attr-defined] + and expr._depth < 2 # type: ignore[attr-defined] # todo: avoid this one? and expr._root_names is not None # type: ignore[attr-defined] )