Skip to content

BUG: Retain index when merging on an index #59646

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

Closed
wants to merge 3 commits into from

Conversation

rob-sil
Copy link
Contributor

@rob-sil rob-sil commented Aug 28, 2024

Since join uses a merge internally, changing the index returned by merge would cause problems for join. To prevent this, I introduced a new argument that would control which index is returned by a merge operation. I also separated out the logic that determined what index to use from the code that created the indexers. Not sure this was the best way to fix this; apologies if I bit off more than I could chew.

This commit introduces an index argument that tells merging how
to choose the output index. I moved the logic determining which
index to use into _MergeOperation.__init__ while moving the logic
for calculating the index to the end of the _get_join_info method.
Note: I did not adjust the logic in the case when merging on both
indexes (or an index and a multiindex).

This commit also introduces a function merge_pick_index so that
internal uses of merge can pick where they get the index from.
Specifically, join uses merge under the hood, but wants the old
merge index sources. Now, join specifies the index source so it
wont be affected by changing merge's index behavior.

This commit should not affect behavior.
This commit changes the index source to fix the bug. It also
corrects many tests which tested for the old indexes.
@rob-sil rob-sil marked this pull request as ready for review August 28, 2024 20:48
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Sep 28, 2024
@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: pd.merge has unexpected behaviour when joining on index / column
2 participants