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

chore: remove some expr._kwargs defaults #1747

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion narwhals/_arrow/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def agg_arrow(
function_name = remove_prefix(expr._function_name, "col->")

if function_name in {"std", "var"}:
option = pc.VarianceOptions(ddof=expr._kwargs.get("ddof", 1))
option = pc.VarianceOptions(ddof=expr._kwargs["ddof"])
elif function_name in {"len", "n_unique"}:
option = pc.CountOptions(mode="all")
elif function_name == "count":
Expand Down
4 changes: 1 addition & 3 deletions narwhals/_dask/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ def agg_dask(

function_name = remove_prefix(expr._function_name, "col->")
kwargs = (
{"ddof": expr._kwargs.get("ddof", 1)}
if function_name in {"std", "var"}
else {}
{"ddof": expr._kwargs["ddof"]} if function_name in {"std", "var"} else {}
)

agg_function = POLARS_TO_DASK_AGGREGATIONS.get(function_name, function_name)
Expand Down
4 changes: 2 additions & 2 deletions narwhals/_pandas_like/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,12 @@ def func(df: PandasLikeDataFrame) -> list[PandasLikeSeries]:
df = df.with_columns(~plx.col(*self._root_names).is_null())

if self._function_name == "col->shift":
kwargs = {"periods": self._kwargs.get("n", 1)}
kwargs = {"periods": self._kwargs["n"]}
elif self._function_name == "col->rank":
_method = self._kwargs.get("method", "average")
kwargs = {
"method": "first" if _method == "ordinal" else _method,
"ascending": not self._kwargs.get("descending", False),
"ascending": not self._kwargs["descending"],
"na_option": "keep",
"pct": False,
}
Expand Down
5 changes: 2 additions & 3 deletions narwhals/_pandas_like/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,13 @@ def agg_pandas( # noqa: PLR0915
is_n_unique = function_name == "nunique"
is_std = function_name == "std"
is_var = function_name == "var"
ddof = expr._kwargs.get("ddof", 1)
for root_name, output_name in zip(expr._root_names, expr._output_names):
if is_n_unique:
nunique_aggs[output_name] = root_name
elif is_std and ddof != 1:
elif is_std and (ddof := expr._kwargs["ddof"]) != 1:
std_aggs[ddof][0].append(root_name)
std_aggs[ddof][1].append(output_name)
elif is_var and ddof != 1:
elif is_var and (ddof := expr._kwargs["ddof"]) != 1:
var_aggs[ddof][0].append(root_name)
var_aggs[ddof][1].append(output_name)
else:
Expand Down
2 changes: 1 addition & 1 deletion narwhals/_spark_like/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_spark_function(function_name: str, **kwargs: Any) -> Column:

return partial(
_std if function_name == "std" else _var,
ddof=kwargs.get("ddof", 1),
ddof=kwargs["ddof"],
np_version=parse_version(np.__version__),
)
from pyspark.sql import functions as F # noqa: N812
Expand Down
Loading