-
Notifications
You must be signed in to change notification settings - Fork 210
chore: remove more kwargs from dask, dont treat ddof as expressifiable arg
#2059
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
Changes from 2 commits
6ed04d0
52b80b2
bd235f3
568b55b
565cb8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -48,7 +48,9 @@ def __init__( | |||||||||||
| alias_output_names: Callable[[Sequence[str]], Sequence[str]] | None, | ||||||||||||
| backend_version: tuple[int, ...], | ||||||||||||
| version: Version, | ||||||||||||
| kwargs: dict[str, Any], | ||||||||||||
| # Kwargs with metadata which we may need in group-by agg | ||||||||||||
| # (e.g. `ddof` for `std` and `var`). | ||||||||||||
| kwargs: dict[str, Any] | None = None, | ||||||||||||
| ) -> None: | ||||||||||||
| self._call = call | ||||||||||||
| self._depth = depth | ||||||||||||
|
|
@@ -57,7 +59,7 @@ def __init__( | |||||||||||
| self._alias_output_names = alias_output_names | ||||||||||||
| self._backend_version = backend_version | ||||||||||||
| self._version = version | ||||||||||||
| self._kwargs = kwargs | ||||||||||||
| self._kwargs = kwargs or {} | ||||||||||||
|
|
||||||||||||
| def __call__(self: Self, df: DaskLazyFrame) -> Sequence[dx.Series]: | ||||||||||||
| return self._call(df) | ||||||||||||
|
|
@@ -110,7 +112,6 @@ def func(df: DaskLazyFrame) -> list[dx.Series]: | |||||||||||
| alias_output_names=None, | ||||||||||||
| backend_version=backend_version, | ||||||||||||
| version=version, | ||||||||||||
| kwargs={}, | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| @classmethod | ||||||||||||
|
|
@@ -133,14 +134,14 @@ def func(df: DaskLazyFrame) -> list[dx.Series]: | |||||||||||
| alias_output_names=None, | ||||||||||||
| backend_version=backend_version, | ||||||||||||
| version=version, | ||||||||||||
| kwargs={}, | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| def _from_call( | ||||||||||||
| self: Self, | ||||||||||||
| # First argument to `call` should be `dx.Series` | ||||||||||||
| call: Callable[..., dx.Series], | ||||||||||||
| expr_name: str, | ||||||||||||
| kwargs: dict[str, Any] | None = None, | ||||||||||||
| **expressifiable_args: Self | Any, | ||||||||||||
| ) -> Self: | ||||||||||||
| def func(df: DaskLazyFrame) -> list[dx.Series]: | ||||||||||||
|
|
@@ -163,7 +164,7 @@ def func(df: DaskLazyFrame) -> list[dx.Series]: | |||||||||||
| alias_output_names=self._alias_output_names, | ||||||||||||
| backend_version=self._backend_version, | ||||||||||||
| version=self._version, | ||||||||||||
| kwargs={**self._kwargs, **expressifiable_args}, | ||||||||||||
| kwargs=kwargs, | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| def alias(self: Self, name: str) -> Self: | ||||||||||||
|
|
@@ -310,12 +311,16 @@ def max(self: Self) -> Self: | |||||||||||
|
|
||||||||||||
| def std(self: Self, ddof: int) -> Self: | ||||||||||||
| return self._from_call( | ||||||||||||
| lambda _input, ddof: _input.std(ddof=ddof).to_series(), "std", ddof=ddof | ||||||||||||
| lambda _input: _input.std(ddof=ddof).to_series(), | ||||||||||||
| "std", | ||||||||||||
| kwargs={"ddof": ddof}, | ||||||||||||
| ) | ||||||||||||
|
Comment on lines
312
to
317
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to #2059 (comment) and # Kwargs with metadata which we may need in group-by agg
# (e.g. `ddof` for `std` and `var`).
kwargs: dict[str, Any] | None = None,I'm not following why narwhals/narwhals/_dask/group_by.py Lines 54 to 55 in 4dda548
narwhals/narwhals/_dask/group_by.py Lines 148 to 150 in 4dda548
Am I reading this wrong, or are the same |
||||||||||||
|
|
||||||||||||
| def var(self: Self, ddof: int) -> Self: | ||||||||||||
| return self._from_call( | ||||||||||||
| lambda _input, ddof: _input.var(ddof=ddof).to_series(), "var", ddof=ddof | ||||||||||||
| lambda _input: _input.var(ddof=ddof).to_series(), | ||||||||||||
| "var", | ||||||||||||
| kwargs={"ddof": ddof}, | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| def skew(self: Self) -> Self: | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we call this
call_kwargsi.e.kwargsfor thecallfunction ?(Just to clarify these kwargs are not passed to
_from_callitself)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EdAbati Couldn't you just pass
callas apartialin the cases where this is needed?So instead of
call,call_kwargs- you'd havecall.func,call.keywords.But the keywords themselves aren't exposed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not know that
functools.partialstored keywords like that, thanks!Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might need to use
operator.methodcallerinstead, if you don't know the class that would be passed.E.g.
partialwould work if you could dopartial(dx.Series.std, ddof=ddof).But where it might be
dx._groupby.GroupBy.std, using the method name would be more widely acceptednarwhals/narwhals/_dask/group_by.py
Lines 54 to 55 in 4dda548
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that why you're storing
function_name, in addition to thelambda?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, that's right