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

Default empty DataFrame to dtype=object #1783

Closed
dalejung opened this issue Aug 19, 2012 · 3 comments

Comments

@dalejung
Copy link
Contributor

commented Aug 19, 2012

I ran into the following :

import pandas as pd

data = {}
columns = ['symbol', 'price']
df = pd.DataFrame(data, columns=columns)

df.symbol == 'AAPL'
# TypeError: Could not compare <type 'str'> type with Series

The problem being that an empty dataframe's dtype defaults to float. I've adjusted for it by checking the len of data and setting the dtype to object when at 0. But I feel like an empty DataFrame should act like an empty list, valid for all list operations. Which in lieu of #549, means casting the widest net possible with dtype=object.

@wesm

This comment has been minimized.

Copy link
Member

commented Sep 18, 2012

Taking a look at this. I'm amazed (disturbed, a little?) so far how little code I'm having to touch (and how few tests are breaking as a result) to make this change

@dalejung

This comment has been minimized.

Copy link
Contributor Author

commented Sep 18, 2012

<MrBurns>Excellent...</MrBurns>

I think the empty DataFrame Constructor is a corner case that short-circuits with a len check. So I can't imagine much depends on the float behavior.

@wesm wesm closed this in 852a994 Sep 18, 2012

@wesm

This comment has been minimized.

Copy link
Member

commented Sep 18, 2012

Done. Hopefully won't wreak too much havoc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.