Skip to content

REGR: pivot changing index name of input object #52630

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

Merged
merged 1 commit into from
Apr 12, 2023
Merged

Conversation

phofl
Copy link
Member

@phofl phofl commented Apr 12, 2023

@phofl phofl added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Regression Functionality that used to work in a prior pandas version labels Apr 12, 2023
@phofl phofl added this to the 2.0.1 milestone Apr 12, 2023
@@ -519,6 +519,8 @@ def pivot(
# If columns is None we will create a MultiIndex level with None as name
# which might cause duplicated names because None is the default for
# level names
data = data.copy(deep=False)
data.index = data.index.copy()
data.index.names = [
Copy link
Member

Choose a reason for hiding this comment

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

Is there an opportunity to defer doing this (and avoiding the copy) if we push this to the if/else branches below?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both are shallow copies and should take any time compared to the actual pivot op?

Copy link
Member

Choose a reason for hiding this comment

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

That's fair. Might be a cleanup opportunity in the future but ok as it fixes the regression

@mroeschke mroeschke merged commit 37bd0fd into pandas-dev:main Apr 12, 2023
@mroeschke
Copy link
Member

Thanks @phofl

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Apr 12, 2023
@phofl phofl deleted the 52629 branch April 12, 2023 21:08
mroeschke pushed a commit that referenced this pull request Apr 12, 2023
…f input object) (#52636)

Backport PR #52630: REGR: pivot changing index name of input object

Co-authored-by: Patrick Hoefler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: DataFrame.pivot mutates empty index.name attribute with typing._LiteralGenericAlias
2 participants