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

BUG: pivot_table with margins and numeric columns #55933

Merged
merged 4 commits into from
Nov 20, 2023

Conversation

quangngd
Copy link
Contributor

@quangngd quangngd commented Nov 13, 2023

@quangngd quangngd changed the title 29576 BUG: pivot_table with margins and numeric columns Nov 13, 2023
@mroeschke mroeschke added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Nov 13, 2023
@mroeschke mroeschke added this to the 2.2 milestone Nov 14, 2023
# GH#26568. Use names instead of indices in case of numeric names
new_order_indices = [len(cols)] + list(range(len(cols)))
new_order_names = [row_margin.index.names[i] for i in new_order_indices]
row_margin.index = row_margin.index.reorder_levels(new_order_names)
Copy link
Member

Choose a reason for hiding this comment

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

Are row_margin.index.names guaranteed to be unique?

Copy link
Contributor Author

@quangngd quangngd Nov 17, 2023

Choose a reason for hiding this comment

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

In this case, row_margin.index.names are the names of the columns in the original df. They should be unique. If user try to pivot_table on a df with duplicated column names, upstream code would scream first.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation. Could you resolve the merge conflict otherwise looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved

@mroeschke mroeschke merged commit 91af4fa into pandas-dev:main Nov 20, 2023
33 of 34 checks passed
@mroeschke
Copy link
Member

Thanks @quangngd

phofl pushed a commit to phofl/pandas that referenced this pull request Nov 21, 2023
* fix and add test

* add whatsnew

* rm comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: pivot_table with margins=True and numeric columns is buggy
2 participants