Skip to content

Index created from empty generator raises TypeError #21470

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
Liam3851 opened this issue Jun 13, 2018 · 0 comments · Fixed by #21481
Closed

Index created from empty generator raises TypeError #21470

Liam3851 opened this issue Jun 13, 2018 · 0 comments · Fixed by #21481
Labels
Bug Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@Liam3851
Copy link
Contributor

Code Sample, a copy-pastable example if possible

# returns Index([], dtype='object')
pd.Index([]) 

# returns Index(['a', 'b', 'c'], dtype='object')
pd.Index(x for x in ['a', 'b', 'c'])

# raises TypeError: Cannot infer number of levels from empty list
pd.Index(x for x in []) 

Problem description

The Index constructor accepts most generators/iterables without issue as if they were a realized list. However, if the generator is empty, it raises an error. This is different from the behavior of calling the Index constructor on an empty list. This is a regression since 0.19.2.

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: 576d5c6 python: 3.6.5.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 62 Stepping 4, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.24.0.dev0+103.g576d5c6b7
pytest: 3.6.0
pip: 10.0.1
setuptools: 39.2.0
Cython: 0.28.3
numpy: 1.14.2
scipy: 1.0.0
pyarrow: 0.8.0
xarray: 0.10.6
IPython: 6.4.0
sphinx: 1.7.5
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.3
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.2.2
openpyxl: 2.5.3
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.5
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.8
pymysql: 0.8.1
psycopg2: None
jinja2: 2.10
s3fs: 0.1.5
fastparquet: 0.1.5
pandas_gbq: None
pandas_datareader: None

@jschendel jschendel added Bug Regression Functionality that used to work in a prior pandas version labels Jun 14, 2018
Liam3851 added a commit to Liam3851/pandas that referenced this issue Jun 14, 2018
Liam3851 added a commit to Liam3851/pandas that referenced this issue Jun 14, 2018
@jreback jreback added this to the 0.23.2 milestone Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants