Skip to content
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

Join on multi-index drops the index names when specifying "on" and "how=outer" #22820

Closed
wraitii opened this issue Sep 24, 2018 · 1 comment
Closed

Comments

@wraitii
Copy link

wraitii commented Sep 24, 2018

Code Sample

import pandas as pd

df1 = pd.DataFrame(data={'i': range(0,100),'i2': range(0,100), 'u': range(200,300)}).set_index(['i','i2'])
df2 = pd.DataFrame(data={'i': range(0,100),'i2': range(0,100), 'v': range(200,300)}).set_index(['i','i2'])

ok = df1.join(df2, how="outer").head(5)
ok.index.names # ['i','i2']
bug = df1.join(df2, on=['i','i2'], how="outer").head(5)
bug.index.names # [None, None]

Problem description

When using pandas' DataFrame join function, specifying "on" with a multiple index and an outer join drops the index names. This seems buggy, as it doesn't do it on single-index or when not specifying "on" or "outer". I am not sure it's actually buggy, as in it could be by design, but it's not documented either way.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Darwin
OS-release: 17.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
LOCALE: fr_FR.UTF-8

pandas: 0.23.0
pytest: 3.5.1
pip: 10.0.1
setuptools: 39.1.0
Cython: 0.28.2
numpy: 1.14.3
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.4.0
sphinx: 1.7.4
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.3
numexpr: 2.6.5
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.3
xlrd: 1.1.0
xlwt: 1.2.0
xlsxwriter: 1.0.4
lxml: 4.2.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.7
pymysql: None
psycopg2: 2.7.5 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@mroeschke
Copy link
Member

I think this was fixed in the latest development cycle and will be available in the next release (0.24.0) coming soon. xref #20452

In [62]: bug = df1.join(df2, on=['i','i2'], how="outer").head(5)
    ...: bug.index.names
Out[62]: FrozenList(['i', 'i2'])

In [64]: pd.__version__
Out[64]: '0.24.0rc1+1.g33f91d8f9'

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

No branches or pull requests

2 participants