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

REGR: setitem with part of a MultiIndex raises #54875

Closed
rhshadrach opened this issue Aug 30, 2023 · 0 comments · Fixed by #54885
Closed

REGR: setitem with part of a MultiIndex raises #54875

rhshadrach opened this issue Aug 30, 2023 · 0 comments · Fixed by #54885
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@rhshadrach
Copy link
Member

On 2.0.x:

df = pd.DataFrame({'a': [1, 2, 3], 'b': [3, 4, 5], 'c': 6, 'd': 7}).set_index(['a', 'b', 'c'])
ser = pd.Series(8, index=df.index.droplevel('c'))

print(df)
#        d
# a b c
# 1 3 6  7
# 2 4 6  7
# 3 5 6  7

print(ser)
# a  b
# 1  3    8
# 2  4    8
# 3  5    8
# dtype: int64

df['d'] = ser
print(df)
#        d
# a b c
# 1 3 6  8
# 2 4 6  8
# 3 5 6  8

On main and 2.1.0rc this raises:

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

A git bisect points at

commit ac3153b30a611d2593b002ca5d9ff22a2bb30af0
Author: Luke Manley <[email protected]>
Date:   Mon Jul 10 13:51:37 2023 -0400

    PERF: MultiIndex set and indexing operations (#53955)
    
    * PERF: MultiIndex set and indexing ops
    
    * whatsnew
    
    * convert to generator

 doc/source/whatsnew/v2.1.0.rst |  1 +
 pandas/_libs/index.pyx         | 17 +++++++++--------
 pandas/core/indexes/multi.py   | 13 +++++++++++++
 3 files changed, 23 insertions(+), 8 deletions(-)

cc @lukemanley

@rhshadrach rhshadrach added Bug Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version labels Aug 30, 2023
@phofl phofl added this to the 2.1.1 milestone Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants