-
Notifications
You must be signed in to change notification settings - Fork 118
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
feat: support std and var with ddof !=1 in pandas-like group by #1645
Conversation
narwhals/_pandas_like/group_by.py
Outdated
# Invert the dict to have root_name: output_name | ||
# TODO(FBruzzesi): Account for duplicates | ||
columns={v: k for k, v in output_to_root_name_mapping.items()}, |
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.
π€ in case someone does .agg(nw.col('a').std(ddof=1).alias('b'), nw.col('a').std(ddof=1).alias('c'))
? hmm yeah i guess it's possible
btw, since cuDF have no introduced cudf.NamedAgg
, we could use that if it makes all this logic a bit easier
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.
Yes correct, similarly to simple aggs.
To avoid an explosion in the number of lists to keep track of, maybe there is a better data structure. I will think about it a bit, yet aside that specific case, this PR should be ready
narwhals/_pandas_like/group_by.py
Outdated
[ | ||
grouped[std_root_names] | ||
.std(ddof=ddof) | ||
.set_axis(std_output_names, axis="columns", copy=False) |
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.
@MarcoGorelli how bad is it to use set_axis
to rename the columns? What's the alternative? Our rename
does a mapping, yet here we could do:
grouped[["b", "b"]].std(ddof=2).set_axis(["c", "d"], axis="columns")
For once we are exploiting some pandas weirdness π
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.
Should be fine let's just use copy=false
oh nice
|
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.
seriously awesome work here @FBruzzesi !
What type of PR is this? (check all applicable)
Related issues
group_by
context ignores expr argumentsΒ #1606Checklist
If you have comments or can explain your changes, please do so below