Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: move maybe_evaluate_expr out of for loop in reuse_series_implementation #1217

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions narwhals/_expression_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,21 @@ def reuse_series_implementation(
plx = expr.__narwhals_namespace__()

def func(df: CompliantDataFrame) -> list[CompliantSeries]:
out: list[CompliantSeries] = []
for column in expr._call(df): # type: ignore[arg-type]
_out = getattr(column, attr)(
*[maybe_evaluate_expr(df, arg) for arg in args],
**{
arg_name: maybe_evaluate_expr(df, arg_value)
for arg_name, arg_value in kwargs.items()
},
_args = [maybe_evaluate_expr(df, arg) for arg in args]
_kwargs = {
arg_name: maybe_evaluate_expr(df, arg_value)
for arg_name, arg_value in kwargs.items()
}

out: list[CompliantSeries] = [
plx._create_series_from_scalar(
getattr(column, attr)(*_args, **_kwargs),
column, # type: ignore[arg-type]
)
if returns_scalar:
out.append(plx._create_series_from_scalar(_out, column)) # type: ignore[arg-type]
else:
out.append(_out)
if returns_scalar
else getattr(column, attr)(*_args, **_kwargs)
for column in expr._call(df) # type: ignore[arg-type]
]
if expr._output_names is not None and (
[s.name for s in out] != expr._output_names
): # pragma: no cover
Expand Down
Loading