Skip to content

DataFrame constructor with MultiIndex DataFrame raises ValueError #26459

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
simonjayhawkins opened this issue May 19, 2019 · 1 comment
Closed
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors MultiIndex

Comments

@simonjayhawkins
Copy link
Member

xref #26451

import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randn(3, 3),
               columns=[['i', 'i', 'j'], ['A', 'A', 'B']],
               index=[['i', 'i', 'j'], ['X', 'X', 'Y']])
pd.DataFrame(df.iloc[[0, 1]], index=['X', 'X'])

Problem description

The error message is self-explanatory, but this case should work?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\simon\OneDrive\code\pandas-simonjayhawkins\pandas\core\frame.py", line 389, in __init__
    dtype=dtype, copy=copy)
  File "C:\Users\simon\OneDrive\code\pandas-simonjayhawkins\pandas\core\generic.py", line 147, in _init_mg
r
    copy=False)
  File "C:\Users\simon\OneDrive\code\pandas-simonjayhawkins\pandas\core\internals\managers.py", line 1189,
 in reindex_axis
    limit=limit)
  File "C:\Users\simon\OneDrive\code\pandas-simonjayhawkins\pandas\core\indexes\multi.py", line 2245, in r
eindex
    raise ValueError("cannot handle a non-unique multi-index!")
ValueError: cannot handle a non-unique multi-index!

Expected Output

          i                   j
          A         A         B
X  0.097722  0.726944  2.751392
X  0.396623 -0.564745 -0.153548

Output of pd.show_versions()

INSTALLED VERSIONS

commit: 5a286e4
python: 3.7.3.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: None.None

pandas: 0.25.0.dev0+584.g5a286e458
pytest: 4.4.2
pip: 19.1.1
setuptools: 40.6.3
Cython: 0.29.7
numpy: 1.16.3
scipy: 1.2.1
pyarrow: 0.11.1
xarray: 0.12.1
IPython: 7.5.0
sphinx: 2.0.1
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: 1.2.1
tables: 3.5.1
numexpr: 2.6.9
feather: None
matplotlib: 3.0.3
openpyxl: 2.6.2
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.8
lxml.etree: 4.3.3
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.3
pymysql: None
psycopg2: None
jinja2: 2.10.1
s3fs: 0.2.1
fastparquet: 0.3.0
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@jbrockmendel jbrockmendel added the Constructors Series/DataFrame/Index/pd.array Constructors label Jul 23, 2019
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Apr 23, 2020
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@mroeschke
Copy link
Member

Based on #42568 which is linked near the exception it appears this is intentional so closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors MultiIndex
Projects
None yet
Development

No branches or pull requests

3 participants