Skip to content

BUG: Joining dataframe with single-level MultiIndex fails #41537

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 2 tasks
soerenwolfers opened this issue May 18, 2021 · 1 comment
Closed
1 of 2 tasks

BUG: Joining dataframe with single-level MultiIndex fails #41537

soerenwolfers opened this issue May 18, 2021 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@soerenwolfers
Copy link

soerenwolfers commented May 18, 2021

  • I have checked that this issue has not already been reported.
    There is BUG/API: index.array for RangeIndex, MultiIndex #37277 which is about the same error message but which isn't about the fact that this shows up in a common operation like joining. Maybe there is a way to make the join work without fixing the underlying issue?

  • I have confirmed this bug exists on the latest version of pandas.
    Unfortunately my work doesn't allow me to test this on latest pandas versions, but given the related issue above and given that I haven't found this issue reported anywhere, I would be surprised if this was fixed in the meantime. I apologize if it was.


Code Sample, a copy-pastable example

df = pd.DataFrame(
    np.random.normal(size=[4,1]), 
    index=pd.MultiIndex.from_product([['a', 'b'], [0.1, 0.2]]),
    columns=['col0']
).rename_axis(index=['level0', 'level1'])
df
df2 = pd.DataFrame(
    np.random.normal(size=[2,1]),
    #index=pd.Index(['a', 'b']),
    index=pd.MultiIndex.from_product([['a', 'b']]),
    columns=['col1']
).rename_axis(index=['level0'])
display(df)
display(df2)
df.join(df2, on=['level0'])

Problem description

Throws an error

Expected Output

Throws no error. Uncomment the commented line above and comment the line below. This should be functionally equivalent.

PS: This probably doesn't belong here, but if I replace the join by a merge it works, but the level1 of the MultiIndex disappears, making it useless for me.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : b5958ee
python : 3.6.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.17134
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : None.None

pandas : 1.1.5
numpy : 1.17.4

@soerenwolfers soerenwolfers added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 18, 2021
@soerenwolfers soerenwolfers changed the title BUG: BUG: Joining dataframes with single-level MultiIndex May 18, 2021
@soerenwolfers soerenwolfers changed the title BUG: Joining dataframes with single-level MultiIndex BUG: Joining dataframe with single-level MultiIndex fails May 18, 2021
@phofl
Copy link
Member

phofl commented May 18, 2021

This is a duplicate of #36909 and is fixed on master

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