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: MultiIndex.isin() raises TypeError when given a generator in v2, works in v1.5 #52568

Closed
3 tasks done
tcuisset opened this issue Apr 10, 2023 · 1 comment · Fixed by #52572
Closed
3 tasks done
Labels
Milestone

Comments

@tcuisset
Copy link

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

# Works
pd.Index([0]).isin((x for x in [0]))

# Used to work in v1.5, raises TypeError in v2
pd.MultiIndex.from_tuples([(1, 2)]).isin((x for x in [(1, 2)]))

Issue Description

Calling MultiIndex.isin(values) with values being a generator expression raises TypeError: object of type 'generator' has no len() in Pandas v2, whilst it worked in Pandas v1.5.
Index.isin still works with a generator expression.

The regression seems to come from #51605 .

Expected Behavior

Generator expressions to work with isin (or at least to behave consistently between Index.isin and MultiIndex.isin)

Installed Versions

Tested on latest pandas :

INSTALLED VERSIONS ------------------ commit : e9e034b python : 3.10.6.final.0 python-bits : 64 OS : Linux OS-release : 5.15.0-69-generic Version : #76-Ubuntu SMP Fri Mar 17 17:19:29 UTC 2023 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 2.1.0.dev0+463.ge9e034badb
numpy : 1.25.0.dev0+1075.g1307defe4
pytz : 2023.3
dateutil : 2.8.2
setuptools : 59.6.0
pip : 22.0.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

and on v1.5 :

INSTALLED VERSIONS

commit : 2e218d1
python : 3.10.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-69-generic
Version : #76-Ubuntu SMP Fri Mar 17 17:19:29 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.3
numpy : 1.24.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 59.6.0
pip : 22.0.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@tcuisset tcuisset added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 10, 2023
@phofl
Copy link
Member

phofl commented Apr 10, 2023

Date:   Fri Feb 24 22:16:21 2023 +0100

    Backport PR #51605 on branch 2.0.x (REGR: MultiIndex.isin with empty iterable raising) (#51617)
    
    Backport PR #51605: REGR: MultiIndex.isin with empty iterable raising

@phofl phofl added MultiIndex isin isin method and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 10, 2023
@phofl phofl added this to the 2.0.1 milestone Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants