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

BUG: Regression in 2.1.0 when inserting usign MultiIndex frames #54909

Closed
3 tasks done
bashtage opened this issue Aug 31, 2023 · 2 comments
Closed
3 tasks done

BUG: Regression in 2.1.0 when inserting usign MultiIndex frames #54909

bashtage opened this issue Aug 31, 2023 · 2 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@bashtage
Copy link
Contributor

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

a = pd.MultiIndex.from_arrays([["a","a"],["b","b"]])
b = pd.MultiIndex.from_arrays([["a"]])
df = pd.DataFrame(index=a)
s = pd.Series([0.4],index=b)
df["new_col"]=s

Issue Description

When inserting a Series with a smaller MultiIndex, pandas 2.1.0 will raise

AssertionError: Length of new_levels (1) must be same as self.nlevels (2)

This was not the case with pandas < 2.1 (including 2.0.3).

In pseudo code, the existing df has an MultiIndex like

[["a", "a"],
 ["a", "b"]]

while the Series to be inserted as a MultIndex like

[["a"],
 ["a"]]

so that it aligns on the first level. Previously this would expand.

Expected Behavior

Insertion of smaller MultiIndex into larger MultiIndex should work as it previously has.

Installed Versions

INSTALLED VERSIONS

commit : ba1cccd
python : 3.9.17.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22621
machine : AMD64
processor : AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 2.1.0
numpy : 1.25.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.2.1
Cython : 0.29.36
pytest : 7.4.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.14.0
pandas_datareader : None
bs4 : None
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.3
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@bashtage bashtage added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 31, 2023
@mroeschke
Copy link
Member

I think this might have been fixed by #54885

@phofl
Copy link
Member

phofl commented Aug 31, 2023

Yep fixed, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

3 participants