Skip to content

Commit eb93073

Browse files
committed
move maybe_evaluate_expr out of for loop
1 parent 90836bd commit eb93073

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

narwhals/_expression_parsing.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,21 @@ def reuse_series_implementation(
219219
plx = expr.__narwhals_namespace__()
220220

221221
def func(df: CompliantDataFrame) -> list[CompliantSeries]:
222-
out: list[CompliantSeries] = []
223-
for column in expr._call(df): # type: ignore[arg-type]
224-
_out = getattr(column, attr)(
225-
*[maybe_evaluate_expr(df, arg) for arg in args],
226-
**{
227-
arg_name: maybe_evaluate_expr(df, arg_value)
228-
for arg_name, arg_value in kwargs.items()
229-
},
222+
_args = [maybe_evaluate_expr(df, arg) for arg in args]
223+
_kwargs = {
224+
arg_name: maybe_evaluate_expr(df, arg_value)
225+
for arg_name, arg_value in kwargs.items()
226+
}
227+
228+
out: list[CompliantSeries] = [
229+
plx._create_series_from_scalar(
230+
getattr(column, attr)(*_args, **_kwargs),
231+
column, # type: ignore[arg-type]
230232
)
231-
if returns_scalar:
232-
out.append(plx._create_series_from_scalar(_out, column)) # type: ignore[arg-type]
233-
else:
234-
out.append(_out)
233+
if returns_scalar
234+
else getattr(column, attr)(*_args, **_kwargs)
235+
for column in expr._call(df) # type: ignore[arg-type]
236+
]
235237
if expr._output_names is not None and (
236238
[s.name for s in out] != expr._output_names
237239
): # pragma: no cover

0 commit comments

Comments
 (0)