-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
API: GH4633, bool(obj) behavior, raise on __nonzero__ always #4657
Conversation
The only change I might make is to include the note you had previously about using 'empty', so maybe: ValueError: The truth value of an array with more than one element is ambiguous. Use a.empty(), a.any() or a.all(). |
will do |
@jreback sorry, missed your earlier comment - anyways looks good though! |
The one nice thing to do would be to add something to the docs that specifically quotes this exception so that someone using pandas for the first time can search for it. Either with this PR or as a todo for later on. |
sure....where do you think should go? boolean indexing (maybe a mention of NOT using and and using '&' instead) |
I think that's a good place - caveats and gotchas probably is another good place - http://pandas.pydata.org/pandas-docs/dev/gotchas.html . I'm thinking something like:
And maybe link to docs on any, all, empty? |
@jtratner |
@@ -531,7 +531,8 @@ def empty(self): | |||
return not all(len(self._get_axis(a)) > 0 for a in self._AXIS_ORDERS) | |||
|
|||
def __nonzero__(self): | |||
return not self.empty | |||
raise ValueError("The truth value of an array with more than one element is ambiguous. Use a.empty, a.any() or a.all()") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be nice to split this on to multiple lines. your call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In [1]: s = Series(1,index=[1,2])
In [2]: s and s
ValueError: The truth value of an array with more than one element is ambiguous.
Use a.empty, a.any() or a.all()
@wesm ? |
ValueError: The truth value of an array |
@wesm this going back to a more natural, less error prone API (that we did have in 0.11) |
print("I was true") | ||
Traceback | ||
... | ||
ValueError: The truth value of an array. Use a.empty, a.any() or a.all(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(missing) is ambiguous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep..thkxs
BUG: GH4633, rever to GH1073, whereby __nonzero__ always raises for all NDFrame objects
any more comments on this before merging? |
Looks good. |
API: GH4633, bool(obj) behavior, raise on __nonzero__ always
closes #4633
this is a revert to #1073/#1069
now a call to
__nonzero__
raisesValueError
ALWAYSThe following is the behavior
And prevents these fun ones (same for Series/Panel)