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

DataFrame.from_records() KeyError when passed empty list #2633

Closed
pikeas opened this issue Jan 4, 2013 · 4 comments
Closed

DataFrame.from_records() KeyError when passed empty list #2633

pikeas opened this issue Jan 4, 2013 · 4 comments
Assignees
Labels
Milestone

Comments

@pikeas
Copy link

pikeas commented Jan 4, 2013

What it says on the tin. from_records() fails with a KeyError if passed an empty list. If the list is empty, an empty DataFrame should be created, conforming to the other arguments (columns, etc).

@wesm
Copy link
Member

wesm commented Jan 4, 2013

Agreed. Thanks

@changhiskhan
Copy link
Contributor

Which version are you on? This seems to work ok on master:

In [7]: DataFrame.from_records([], index=Index([1,2]))
Out[7]: 
Empty DataFrame
Columns: []
Index: [1, 2]

@pikeas
Copy link
Author

pikeas commented Jan 5, 2013

pd.DataFrame.from_records([], index='foo', columns=['foo', 'bar'])

Looks like I was inaccurate about the error message thrown. The above throws an IndexError. Version 0.10.0.

@ghost ghost assigned wesm Jan 19, 2013
@wesm wesm closed this as completed in dd439c9 Jan 19, 2013
@bmampaey
Copy link

The problem is not solved if the index is specified as a string

In [1]: from pandas import DataFrame, Index                                          

In [2]: DataFrame.from_records([])                                                   
Out[2]: 
Empty DataFrame
Columns: []
Index: []

In [3]: DataFrame.from_records([], index = Index([1,2]))                             
Out[3]: 
Empty DataFrame
Columns: []
Index: [1, 2]

In [4]: DataFrame.from_records([], index='time') 

blah blah
KeyError: 'time'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants