Skip to content

BUG: cannot construct Index of empty tuples #45608

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
2 of 3 tasks
batterseapower opened this issue Jan 25, 2022 · 0 comments · Fixed by #46238
Closed
2 of 3 tasks

BUG: cannot construct Index of empty tuples #45608

batterseapower opened this issue Jan 25, 2022 · 0 comments · Fixed by #46238
Labels
Bug Index Related to the Index class or subclasses Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.).
Milestone

Comments

@batterseapower
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
pd.Index([()]) # Fails, the MultiIndex constructor complains that you "must pass non-zero number of levels/codes"
pd.Index([(), None])[:1] # Works

Issue Description

The index constructor has a special case for when the input list consists purely of tuples. However, it's not aware of the special case in MultiIndex that forbids number of levels == 0. Index should avoid trying to construct a MultiIndex in this case.

(Even better, MultiIndex could just support 0-level indexes. Yes, they are trivial in some sense, but they are also perfectly sensible.)

Expected Behavior

Both lines should evaluate correctly to identical indexes.

Installed Versions

INSTALLED VERSIONS ------------------ commit : 945c9ed python : 3.8.12.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19042 machine : AMD64 processor : Intel64 Family 6 Model 85 Stepping 7, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : English_United Kingdom.1252

pandas : 1.3.4
numpy : 1.21.3
pytz : 2021.3
dateutil : 2.8.2
pip : 21.1.1
setuptools : 58.0.4
Cython : 0.29.24
pytest : 6.2.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.0.2
IPython : 7.29.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : 1.3.2
fsspec : 2021.08.1
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 3.0.0
pyxlsb : None
s3fs : None
scipy : 1.6.2
sqlalchemy : None
tables : 3.6.1
tabulate : None
xarray : 0.19.0
xlrd : 2.0.1
xlwt : None
numba : 0.53.1

@batterseapower batterseapower added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 25, 2022
bennycortese added a commit to bennycortese/pandas that referenced this issue Jan 31, 2022
Merge is necessary because proper changes have been made to a github issue pandas-dev#45608
@mroeschke mroeschke added Index Related to the Index class or subclasses Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 10, 2022
@jreback jreback added this to the 1.5 milestone Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Index Related to the Index class or subclasses Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.).
Projects
None yet
3 participants