pandas icon indicating copy to clipboard operation
pandas copied to clipboard

BUG: Fix metadata mutation in Index set operations (intersection/unio…

Open deniskrds opened this issue 1 month ago • 0 comments

…n) (#63169)

  • [x] closes #63169
  • [x] [Tests added and passed]
  • [x] All [code checks passed]
  • [ ] Added [type annotations]
  • [ ] Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.
  • [ ] If I used AI to develop this pull request, I prompted it to follow AGENTS.md.

Previously, Index.intersection and Index.union (including MultiIndex implementations) would return a direct reference to self (or other) if the result was identical to the input. This allowed side effects where mutating the metadata (e.g. .name) of the result would corrupt the original index.

This change forces a shallow copy (deep=False) in these cases. This preserves the performance benefit of sharing the underlying data array while ensuring the Index container itself is a distinct object with independent metadata.

deniskrds avatar Nov 22 '25 23:11 deniskrds