Skip to content

unhelpful error message with DataFrame constructor and integer MultiIndex DataFrame #26460

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

Open
simonjayhawkins opened this issue May 19, 2019 · 0 comments
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Error Reporting Incorrect or improved errors from pandas

Comments

@simonjayhawkins
Copy link
Member

similar to #26459, but with integer MultiIndex

Code Sample, a copy-pastable example if possible

import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randn(3, 3),
               columns=[[2, 2, 4], [6, 8, 10]],
               index=[[4, 4, 8], [8, 10, 12]])
pd.DataFrame(df.iloc[[0, 1]], index=[8, 10])

Problem description

should either work or give similar message to #26459

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 2254, in r
eindex
    target = MultiIndex.from_tuples(target)
  File "C:\Users\simon\OneDrive\code\pandas-simonjayhawkins\pandas\core\indexes\multi.py", line 400, in fr
om_tuples
    arrays = list(lib.tuples_to_object_array(tuples).T)
  File "pandas\_libs\lib.pyx", line 2230, in pandas._libs.lib.tuples_to_object_array
    def tuples_to_object_array(ndarray[object] tuples):
ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long long'

Expected Output

either

           2                   4
          6         8         10
8   0.402010  0.228705  0.154561
10 -0.331031  1.321493 -0.193243

or

ValueError: cannot handle a non-unique multi-index!

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

@jbrockmendel jbrockmendel added the Constructors Series/DataFrame/Index/pd.array Constructors label Jul 23, 2019
@simonjayhawkins simonjayhawkins added Bug Error Reporting Incorrect or improved errors from pandas labels Apr 25, 2020
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 Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

No branches or pull requests

2 participants