Skip to content
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

BUG: inappropriate error message for DataFrame.from_dict(OrderedDict(...)) #25515

Open
simonjayhawkins opened this issue Mar 2, 2019 · 0 comments
Labels
Bug Error Reporting Incorrect or improved errors from pandas

Comments

@simonjayhawkins
Copy link
Member

see also #22705

Code Sample, a copy-pastable example if possible

from pandas import DataFrame
from collections import OrderedDict
DataFrame.from_dict(
    OrderedDict([('b', 8), ('a', 5), ('a', 6)]))

Note: code sample from exisiting test...

pytest.raises(ValueError, DataFrame.from_dict,
OrderedDict([('b', 8), ('a', 5), ('a', 6)]))

Problem description

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-ee89993a8718> in <module>
      2 from collections import OrderedDict
      3 DataFrame.from_dict(
----> 4     OrderedDict([('b', 8), ('a', 5), ('a', 6)]))

~\Anaconda3\lib\site-packages\pandas\core\frame.py in from_dict(cls, data, orient, dtype, columns)
    983             raise ValueError('only recognize index or columns for orient')
    984 
--> 985         return cls(data, index=index, columns=columns, dtype=dtype)
    986 
    987     def to_dict(self, orient='dict', into=dict):

~\Anaconda3\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy)
    346                                  dtype=dtype, copy=copy)
    347         elif isinstance(data, dict):
--> 348             mgr = self._init_dict(data, index, columns, dtype=dtype)
    349         elif isinstance(data, ma.MaskedArray):
    350             import numpy.ma.mrecords as mrecords

~\Anaconda3\lib\site-packages\pandas\core\frame.py in _init_dict(self, data, index, columns, dtype)
    457             arrays = [data[k] for k in keys]
    458 
--> 459         return _arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
    460 
    461     def _init_ndarray(self, values, index, columns, dtype=None, copy=False):

~\Anaconda3\lib\site-packages\pandas\core\frame.py in _arrays_to_mgr(arrays, arr_names, index, columns, dtype)
   7354     # figure out the index, if necessary
   7355     if index is None:
-> 7356         index = extract_index(arrays)
   7357 
   7358     # don't force copy because getting jammed in an ndarray anyway

~\Anaconda3\lib\site-packages\pandas\core\frame.py in extract_index(data)
   7391 
   7392         if not indexes and not raw_lengths:
-> 7393             raise ValueError('If using all scalar values, you must pass'
   7394                              ' an index')
   7395 

ValueError: If using all scalar values, you must pass an index

Expected Output

Output of pd.show_versions()

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

@mroeschke mroeschke added the Error Reporting Incorrect or improved errors from pandas label Mar 3, 2019
@mroeschke mroeschke added the Bug label Jun 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

No branches or pull requests

2 participants