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

fix: Allow index=None in pivot() #15855

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

fix: Allow index=None in pivot() #15855

wants to merge 10 commits into from

Conversation

ohines
Copy link

@ohines ohines commented Apr 24, 2024

Closes #11592

I ran into this 'backlog' issue and decided to implement a fix.
I don't usually write rust code so apologies if something is a little shaky.

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Apr 24, 2024
Copy link

codecov bot commented Apr 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.38%. Comparing base (a9c8b59) to head (82fd514).
Report is 1 commits behind head on main.

❗ Current head 82fd514 differs from pull request most recent head d03f2c4. Consider uploading reports for the commit d03f2c4 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #15855       +/-   ##
===========================================
+ Coverage   39.14%   80.38%   +41.24%     
===========================================
  Files        1364     1263      -101     
  Lines      167705   165371     -2334     
  Branches     3031        0     -3031     
===========================================
+ Hits        65646   132938    +67292     
+ Misses     101592    32433    -69159     
+ Partials      467        0      -467     
Flag Coverage Δ
python ?
rust ?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ritchie46
Copy link
Member

@MarcoGorelli any opinion on this? I always have to think hard on pivots. ^^

Copy link
Collaborator

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks for working on this!

the expected output looks correct to me - it would be like doing

df.with_columns(_tmp=pl.lit("a")).pivot(
    index="_tmp", columns="foo", values=["N", "M"], aggregate_function=None
).drop("_tmp")

right?

I'll take a look at the implementation next week

Comment on lines 7140 to 7141
Set the index to None to output a single row.
>>> df = pl.DataFrame(
Copy link
Collaborator

Choose a reason for hiding this comment

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

are you sure this renders properly? i think you need an extra blank line

Copy link
Author

Choose a reason for hiding this comment

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

Ah yes I didn't see that. Fixed now.

Copy link
Collaborator

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

For now I'm going to block this (sorry Oliver!) as I'm not really sure about it, see #11592 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame.pivot does not work with index=None even though function signature implies it is acceptable
3 participants