Skip to content

Conversation

@zachyattack23
Copy link

@zachyattack23 zachyattack23 commented Dec 3, 2025

  • Add test for GH#62150
  • Bug was present in 2.3.1, fixed in 3.0.0
  • Test ensures merge works when one df has single-level index and other has multi-level index after reset_index()

Closes #62150

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • 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.

- Add test for GH#62150
- Bug was present in 2.3.1, fixed in 3.0.0
- Test ensures merge works when one df has single-level index
  and other has multi-level index after reset_index()

Closes pandas-dev#62150
Comment on lines 2940 to 2941
# GH#62150 - merging reset MultiIndex when one df has single-level index
# Bug existed in 2.3.1, fixed in 3.0.0, this test prevents regression
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove all the comments (and the comments below) except GH#62150?

Copy link
Author

Choose a reason for hiding this comment

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

Sure

Comment on lines 2944 to 2951
df = DataFrame(data={("column_1", ""): [1, 1], ("column_2", ""): [2, 2]})
df.index = MultiIndex.from_arrays(
[[1, 1], ["metadata_1", "metadata_2"]], names=["index", "metadata"]
)

# Create second dataframe with single index and MultiIndex columns
df2 = DataFrame(data=[1, 1], index=[1, 1]).rename_axis("index", axis=0)
df2.columns = MultiIndex.from_product([["new_data"], [""]])
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned in #62150 (comment), it would be good to construct these DataFrames directly

Copy link
Author

Choose a reason for hiding this comment

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

Gotcha, I'll do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Inconsistent behaviour when merging reset-ed MultiIndex dataframe

2 participants