Skip to content

BUG: pd.merge mixes up the left/right index/on keys in result #43096

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
1 of 3 tasks
hamishdarbyshire opened this issue Aug 18, 2021 · 1 comment
Closed
1 of 3 tasks
Labels
Bug Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@hamishdarbyshire
Copy link

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandas.
  • (optional) I have confirmed this bug exists on the master branch of pandas.

I was reviewing the recent PR for anti-joins and was attempting to come up with a standard test structure, and came across this:

left = pd.DataFrame([[1,1],[2,2],[3,3]], index=[1,2,3], columns=["A", "C"])
   A  C
1  1  1
2  2  2
3  3  3

right = pd.DataFrame([[1,1],[2,2],[4,4]], index=[1,2,4], columns=["B", "C"])
   B  C
1  1  1
2  2  2
4  4  4

pd.merge(left, right, how="left", left_index=True, right_on="B")
      A  C_x  B  C_y
1.0   1    1  1  1.0
2.0   2    2  2  2.0
NaN   3    3  3  NaN

Expected

pd.merge(left, right, how="left", left_index=True, right_on="B")
    A  C_x    B  C_y
1   1    1    1    1
2   2    2    2    2
3   3    3  NaN  NaN
@hamishdarbyshire hamishdarbyshire added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 18, 2021
@phofl
Copy link
Member

phofl commented Aug 18, 2021

Hi, thanks for the report.

This is a duplicate of #28243

@phofl phofl closed this as completed Aug 18, 2021
@phofl phofl added Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 18, 2021
@phofl phofl added this to the No action milestone Aug 18, 2021
@phofl phofl added the Duplicate Report Duplicate issue or pull request label Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

2 participants