Skip to content

Commit

Permalink
dont increase depth for alias close #1
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Feb 20, 2024
1 parent 7072a69 commit 463536e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions narwhals/pandas_like/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion narwhals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
Expand Down

0 comments on commit 463536e

Please sign in to comment.