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

ENH: Improve error message when using DataFrame.from_items instead of DataFrame.from_records #17312

Closed
wesm opened this Issue Aug 22, 2017 · 4 comments

Comments

Projects
None yet
5 participants
@wesm
Member

wesm commented Aug 22, 2017

User reported from an early version of pandas, but this is still present in master:

import pandas

counters = [
    ('a', 98172247543414),
    ('b', 7805009),
    ('c', 1172983),
    ]

df = pandas.DataFrame.from_items(counters)


# Traceback (most recent call last):                                                                                                                
#   File "/home/user/ptest.py", line 12, in <module>                                                                                               
#     df = pandas.DataFrame.from_items(counters)                                                                                                    
#   File "/usr/local/lib/python2.7/dist-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 932, in from_items                
#   File "/usr/local/lib/python2.7/dist-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 947, in _from_arrays              
#   File "/usr/local/lib/python2.7/dist-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 4463, in _arrays_to_mgr           
#   File "/usr/local/lib/python2.7/dist-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 4502, in extract_index            
# ValueError: If using all scalar values, you must must pass an index  
@chris-b1

This comment has been minimized.

Contributor

chris-b1 commented Aug 22, 2017

xref #4916 - not sure there are many usecases left where from_items is needed, possibly could be deprecated in favor of pd.DataFrame(dict(items)) (that's what I personally use)

@jreback

This comment has been minimized.

Contributor

jreback commented Aug 23, 2017

@chris-b1 can you open an issue for the deprecation.

@chris-b1 chris-b1 added this to the Next Major Release milestone Aug 24, 2017

@reidy-p

This comment has been minimized.

Contributor

reidy-p commented Oct 14, 2017

I've been looking at this issue and the problem seems to be that the value in each (key, value) pair should be an array or a Series as noted in the from_items docstring. Would it make sense to raise a ValueError with this message if the user passes a scalar instead of an array or Series as a value?

@jreback

This comment has been minimized.

Contributor

jreback commented Oct 14, 2017

The problem is the user passed a dict, with keys that are all scalars; maybe meant to use a Series (or of course meant to pass values that are array-like)

In [6]: Series(dict(counters))
Out[6]: 
a    98172247543414
b           7805009
c           1172983
dtype: int64

I suppose the error message could be improved

reidy-p added a commit to reidy-p/pandas that referenced this issue Oct 15, 2017

@reidy-p reidy-p referenced this issue Oct 15, 2017

Merged

EHN: Improve from_items error message (#17312) #17881

3 of 4 tasks complete

@jreback jreback modified the milestones: Next Major Release, 0.22.0 Oct 28, 2017

reidy-p added a commit to reidy-p/pandas that referenced this issue Oct 31, 2017

reidy-p added a commit to reidy-p/pandas that referenced this issue Nov 25, 2017

reidy-p added a commit to reidy-p/pandas that referenced this issue Nov 25, 2017

reidy-p added a commit to reidy-p/pandas that referenced this issue Nov 26, 2017

reidy-p added a commit to reidy-p/pandas that referenced this issue Nov 26, 2017

jreback added a commit that referenced this issue Nov 26, 2017

@reidy-p reidy-p referenced this issue Nov 26, 2017

Open

DEPR: let's deprecate #18262

12 of 36 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment