Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: pd.MultiIndex.reindex when the levels are pd.Int64Index behaves differently. #46833

Open
Labels
Closing CandidateMay be closeable, needs more eyeballs Error ReportingIncorrect or improved errors from pandas MultiIndex Typingtype annotations, mypy/pyright type checking Usage Question
@olofahlen

Description

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

mi = pd.MultiIndex.from_tuples([('a', 'b', )])
mi.reindex(mi.to_frame().values) # Works
mi = pd.MultiIndex.from_tuples([(1, 2, )])
mi.reindex(mi.to_frame().values) # Fails with ValueError: Index data must be 1-dimensional.

Issue Description

Passing a list[tuple] to pd.MultiIndex.reindex always works. However, passing a list[list] fails when the levels are all pd.Int64Index, but seems to work otherwise. After calling .values, one typically ends up with a list[list]. It would be useful to have .reindex not fail.

Expected Behavior

Either fail for list[list] or accept both list[list] and list[tuple] with the same behavior. Since pd.DataFrame.values typically gives you list[list], it would be nice to support it so that both examples above work.

Installed Versions

INSTALLED VERSIONS

commit : 4bfe3d0
python : 3.9.10.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19043
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252

pandas : 1.4.2
numpy : 1.22.2
pytz : 2021.3
dateutil : 2.8.2
pip : 22.0.3
setuptools : 60.9.3
Cython : None
pytest : 7.0.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 8.1.1
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : 2.1.0
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closing CandidateMay be closeable, needs more eyeballs Error ReportingIncorrect or improved errors from pandas MultiIndex Typingtype annotations, mypy/pyright type checking Usage Question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /