Skip to content

Commit

Permalink
fixup root names for None case
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Feb 21, 2024
1 parent 5b71873 commit 57280d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions narwhals/pandas_like/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def agg(
for key, name in zip(keys, self._keys):
out[name].append(key)
for expr in exprs:
assert expr._output_names is not None
if len(expr._output_names) != 1:
msg = (
"Multi-output non-elementary aggregations are not supported in group_by.agg.\n"
Expand Down
15 changes: 8 additions & 7 deletions narwhals/pandas_like/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from copy import copy
from typing import TYPE_CHECKING
from typing import Any
from typing import Iterable
Expand Down Expand Up @@ -202,13 +203,13 @@ def func(df: DataFrame | LazyFrame) -> list[Series]:
out.append(plx._create_series_from_scalar(_out, column))
return out

root_names = expr._root_names
for arg in args:
if isinstance(arg, Expr):
root_names.extend(arg._root_names)
for arg in kwargs.values():
if isinstance(arg, Expr):
root_names.extend(arg._root_names)
root_names = copy(expr._root_names)
for arg in list(args) + list(kwargs.values()):
if root_names is not None and isinstance(arg, Expr):
if arg._root_names is not None:
root_names.extend(arg._root_names)
else:
root_names = None

return plx._create_expr_from_callable( # type: ignore[return-value]
func,
Expand Down

0 comments on commit 57280d6

Please sign in to comment.