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

bool() operation on DataFrame should throw ValueError #1069

Closed
dtcaciuc opened this issue Apr 16, 2012 · 3 comments
Closed

bool() operation on DataFrame should throw ValueError #1069

dtcaciuc opened this issue Apr 16, 2012 · 3 comments
Milestone

Comments

@dtcaciuc
Copy link

DataFrame should behave consistently with Series and NumPy arrays when used in boolean comparison. Additionally, should provide consistent all/any behaviour.

>>> from pandas import *
>>> s = Series([1, 2, 3]) 
>>> bool(s)   
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
>>> d = DataFrame([[1,2,3]])
>>> bool(d)
True  # should throw ValueError as well
>>> all(s)
True
>>> all(d)
False # should be True
@dtcaciuc
Copy link
Author

To clarify, this allows for the following to succeed, which is quite counter-intuitive:

>>> from pandas import *
>>> assert DataFrame([1,2,3]) == DataFrame([4,5,6])

@echlebek
Copy link

I think part of the issue is that DataFrame borrows some of its semantics from list, and some from numpy.

bool(dataframe) returns True when it is non-empty, like list. But dataframe_a == dataframe_b returns a new DataFrame of boolean values, whereas list would return a scalar bool. The usual test for this returned data frame, if we were using numpy, would be to call any() on it or all() to observe if some or all of the values are true. But DataFrame does not provide this functionality.

echlebek pushed a commit to echlebek/pandas that referenced this issue Apr 17, 2012
Calling bool() on DataFrame raises issues described in pandas-dev#1069. This
change causes DataFrame to raise a ValueError when called with bool(),
and instead provides a new property, dataframe.empty.
echlebek pushed a commit to echlebek/pandas that referenced this issue Apr 17, 2012
Calling bool() on DataFrame raises issues described in pandas-dev#1069. This
change causes DataFrame to raise a ValueError when called with bool(),
and instead provides a new property, dataframe.empty.
@wesm
Copy link
Member

wesm commented May 7, 2012

I merged in this API change. Hopefully will not cause too many problems.

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

No branches or pull requests

3 participants