Skip to content

Commit b74d56c

Browse files
authored
chore: Refactor _apply_exprs_function internal (#2829)
chore: Refactor _apply_exprs_function internal
1 parent 920e0d1 commit b74d56c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

narwhals/_pandas_like/group_by.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ def _apply_exprs_function(self, exprs: Iterable[PandasLikeExpr]) -> NativeApply:
269269
into_series = ns._series.from_iterable
270270

271271
def fn(df: pd.DataFrame) -> pd.Series[Any]:
272-
out_group = []
273-
out_names = []
274-
for expr in exprs:
275-
results_keys = expr(self.compliant._with_native(df))
276-
for keys in results_keys:
277-
out_group.append(keys.native.iloc[0])
278-
out_names.append(keys.name)
272+
compliant = self.compliant._with_native(df)
273+
results = (
274+
(keys.native.iloc[0], keys.name)
275+
for expr in exprs
276+
for keys in expr(compliant)
277+
)
278+
out_group, out_names = zip(*results) if results else ([], [])
279279
return into_series(out_group, index=out_names, context=ns).native
280280

281281
return fn

0 commit comments

Comments
 (0)