Skip to content

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

Open
@simonjayhawkins

Description

@simonjayhawkins

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugError ReportingIncorrect or improved errors from pandas

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions