Skip to content

BUG: Using None in nested object MultiIndex causes reindex to misalign. #42883

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
3 tasks done
DriesSchaumont opened this issue Aug 4, 2021 · 0 comments · Fixed by #48877
Closed
3 tasks done

BUG: Using None in nested object MultiIndex causes reindex to misalign. #42883

DriesSchaumont opened this issue Aug 4, 2021 · 0 comments · Fixed by #48877
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate MultiIndex Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.).

Comments

@DriesSchaumont
Copy link
Member

  • 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.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

>>> import pandas as pd
>>> index = pd.MultiIndex.from_tuples([(('a', None), 1), (('b', None), 2)])
>>> index2 = pd.MultiIndex.from_tuples([(('b', None), 2), (('a', None), 1)])
>>> df1_dtype = pd.DataFrame([1,2], index=index)
>>> df2_dtype = pd.DataFrame([2,1], index=index2)
>>> df1_dtype.reindex_like(df2_dtype)
              0
(b, None) 2 NaN
(a, None) 1 NaN
>>> import pandas as pd
>>> import numpy as np
>>> index = pd.MultiIndex.from_tuples([(('a', np.nan), 1), (('b', np.nan), 2)])
>>> index2 = pd.MultiIndex.from_tuples([(('b', np.nan), 2), (('a', np.nan), 1)])
>>> df1_dtype = pd.DataFrame([1,2], index=index)
>>> df2_dtype = pd.DataFrame([2,1], index=index2)
>>> df1_dtype.reindex_like(df2_dtype)
            0
(b, nan) 2  2
(a, nan) 1  1

Problem description

I would expect the two indices to align here.

Expected Output

>>> import pandas as pd
>>> index = pd.MultiIndex.from_tuples([(('a', None), 1), (('b', None), 2)])
>>> index2 = pd.MultiIndex.from_tuples([(('b', None), 2), (('a', None), 1)])
>>> df1_dtype = pd.DataFrame([1,2], index=index)
>>> df2_dtype = pd.DataFrame([2,1], index=index2)
>>> df1_dtype.reindex_like(df2_dtype)
            0
(b, None) 2  2
(a, None) 1  1

Output of pd.show_versions()

>>> pd.show_versions()

INSTALLED VERSIONS
------------------
commit           : 226876a55b82324b92449256bab47d431b22310f
python           : 3.8.5.final.0
python-bits      : 64
OS               : Linux
OS-release       : 4.19.128-microsoft-standard
Version          : #1 SMP Tue Jun 23 12:58:10 UTC 2020
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : C.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.4.0.dev0+357.g226876a55b
numpy            : 1.21.1
pytz             : 2021.1
dateutil         : 2.8.2
pip              : 21.2.2
setuptools       : 57.4.0
Cython           : 0.29.24
pytest           : 6.2.4
hypothesis       : 6.14.5
sphinx           : 4.1.2
blosc            : 1.10.4
feather          : None
xlsxwriter       : 1.4.4
lxml.etree       : 4.6.3
html5lib         : 1.1
pymysql          : None
psycopg2         : None
jinja2           : 3.0.1
IPython          : 7.25.0
pandas_datareader: None
bs4              : 4.9.3
bottleneck       : 1.3.2
fsspec           : 2021.05.0
fastparquet      : 0.6.3
gcsfs            : 2021.07.0
matplotlib       : 3.4.2
numexpr          : 2.7.3
odfpy            : None
openpyxl         : 3.0.7
pandas_gbq       : None
pyarrow          : 5.0.0
pyxlsb           : None
s3fs             : None
scipy            : 1.7.0
sqlalchemy       : 1.4.22
tables           : 3.6.1
tabulate         : 0.8.9
xarray           : 0.18.2
xlrd             : 2.0.1
xlwt             : 1.3.0
numba            : 0.53.1
@DriesSchaumont DriesSchaumont added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 4, 2021
@mroeschke mroeschke added MultiIndex Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate MultiIndex Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants