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

feat(python): Add name parameter to GroupBy.len method #15235

Merged
merged 4 commits into from Mar 23, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Mar 22, 2024

Closes #15222.

Seems like a simple/reasonable addition? While adding tests for this, I also found/fixed a bug where a column name is legitimately the empty string, and we reference it from schema_overrides; was getting incorrectly renamed as "column_0".

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Mar 22, 2024
Copy link

codecov bot commented Mar 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.29%. Comparing base (103bb66) to head (33349e2).
Report is 27 commits behind head on main.

❗ Current head 33349e2 differs from pull request most recent head 73f16aa. Consider uploading reports for the commit 73f16aa to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15235      +/-   ##
==========================================
+ Coverage   81.25%   81.29%   +0.04%     
==========================================
  Files        1354     1356       +2     
  Lines      175390   175692     +302     
  Branches     2518     2525       +7     
==========================================
+ Hits       142505   142830     +325     
+ Misses      32404    32379      -25     
- Partials      481      483       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to think on this one a bit, but I think it's a valid addition. The default name can clash, so if you're grouping by a column named len, you cannot use the GroupBy.len method.

Since this is supposed to be a syntactic sugar / ease of use function, it might as well be easy to use... or you might argue the other way and say it should be simple, and for more complex use cases, do not use the syntactic sugar.

Anyway, I think it should be added. If you can address the 2 comments this can be merged!

py-polars/tests/unit/dataframe/test_df.py Outdated Show resolved Hide resolved
py-polars/polars/dataframe/group_by.py Show resolved Hide resolved
@stinodego stinodego changed the title feat(python): allow convenience rename of aggregate len col feat(python): Add name parameter to GroupBy.len method Mar 23, 2024
Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

@stinodego stinodego merged commit 5febd51 into pola-rs:main Mar 23, 2024
12 checks passed
@alexander-beedie alexander-beedie deleted the groupby-len-name branch March 24, 2024 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add parameter name to GroupBy.len()
2 participants