-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
"Or" does not have commutative property (possibly because it catches exceptions silently?) #13806
Comments
FWIW, we follow python's logic here In [40]: float('nan') or 1
Out[40]: nan
In [41]: 1 or float('nan')
Out[41]: 1 Your example is similar, the Thanks to short-circuiting, I don't think you can rely on In [44]: True or this_variable_is_undefined
Out[44]: True The reverse of that throws a NameError.
I suspect you're right 😄 I don't think we can change this behavior though. |
I should also say that you can get the desired output by |
I think I didn't phrase my issue correctly. We agree that short-circuiting may break commutativity. I'm not talking about NaN | True. I'm talking about: If you run |
Ah, you're saying |
@TomAugspurger thank you for getting back to me. This raises an exception to me:
Which is the simplified version we were testing. The code you wrote, doesn't raise an exception for me either. |
Yeah it raises
I think
|
Possibly. I'm more worried about inconsistent behavior inside an or. Look:
|
This boils down to the Series behaviour for
So the comparison never propagates the |
The issue about NaNs in booleans is already discussed in #6528, so closing here as a duplicate. |
@josepablog Whether it should raise or not depends on the outcome of |
@jorisvandenbossche, @TomAugspurger what do you think |
Ah yes, forgot that part of the issue. Is there any precendence for other of the string methods on how they handle errors / NaNs? |
@sinhrks I prefer the current behavior of
We could document this better. This is a common enough gotcha that we should include a warning box in the prose docs. Another option is to add a |
Code Sample, a copy-pastable example if possible
import pandas as pd
Notice that
Series.str.isnumeric
throws an exception on null entries. However, I believe that this may introduce bugs silentlyExpected Output
Expected output is:
2
2
Instead, I get:
3
2
output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Darwin
OS-release: 15.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
pandas: 0.18.1
The text was updated successfully, but these errors were encountered: