Skip to content

REGR: MultiIndex.isin with an empty iterable raises #51599

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
rhshadrach opened this issue Feb 23, 2023 · 1 comment · Fixed by #51605
Closed

REGR: MultiIndex.isin with an empty iterable raises #51599

rhshadrach opened this issue Feb 23, 2023 · 1 comment · Fixed by #51605
Labels
Bug isin isin method MultiIndex Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@rhshadrach
Copy link
Member

On 1.5.x:

df = pd.DataFrame({'a': [1, 1, 2], 'b': [3, 4, 5]}).set_index(['a', 'b'])

print(df.index.isin([]))
# [False False False]

On 2.0.x:

TypeError: Cannot infer number of levels from empty list

Seems like an Index consisting of False is the right answer here.

@rhshadrach rhshadrach added Regression Functionality that used to work in a prior pandas version MultiIndex isin isin method labels Feb 23, 2023
@rhshadrach rhshadrach added this to the 2.0 milestone Feb 23, 2023
@rhshadrach rhshadrach added the Bug label Feb 23, 2023
@rhshadrach
Copy link
Member Author

rhshadrach commented Feb 23, 2023

commit 02d988ca8f5be9ffe8435b7f37c4dd8d43ccd108
Author: Patrick Hoefler
Date:   Tue Sep 20 00:58:34 2022 +0200

    PERF: Improve performance for MultiIndex.isin (#48622)
    
    * PERF: Improve performance for MultiIndex.isin
    
    * PERF: Improve performance for MultiIndex.isin
    
    * Fix gh ref

 asv_bench/benchmarks/multiindex_object.py | 32 +++++++++++++++++++++++++++++++
 doc/source/whatsnew/v1.6.0.rst            |  1 +
 pandas/core/indexes/multi.py              |  3 +--
 3 files changed, 34 insertions(+), 2 deletions(-)

cc @phofl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug isin isin method MultiIndex Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant