BUG: When done as part of pd.Series, NaN | True
is False
which contradicts logic
#51267
Open
3 tasks done
Labels
Uh oh!
There was an error while loading. Please reload this page.
Pandas version checks
Reproducible Example
Issue Description
The result of a bitwise or operator (
|
orpd.Series.__or__()
) should not depend on the order of the operands. Or should be commutative.But in this case, when one of the operands is NaN, pandas violates this law. This seems odd. Numpy doesn't show this inconsistency. Numpy complains that NaN cannot be used with Or.
Pandas silently casts, without any warning.
There's been a StackOverflow issue about this for a long time, but I couldn't find an issue here: https://stackoverflow.com/questions/39000907/pandas-column-selection-non-commutative-bitwise-or-when-selecting-on-str-and-na
Expected Behavior
The result should always be true in bitwise or comparison if one of the operands is true.
It's ok if the user gets a warning or there's an error. But silently making it go false is bad.
Actual behavior
Installed Versions
INSTALLED VERSIONS
commit : 2e218d1
python : 3.10.8.final.0
python-bits : 64
OS : Darwin
OS-release : 22.3.0
Version : Darwin Kernel Version 22.3.0: Thu Jan 5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.5.3
numpy : 1.24.2
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 67.1.0
pip : 23.0
Cython : None
pytest : 7.2.1
hypothesis : None
...
xlrd : None
xlwt : None
zstandard : 0.19.0
tzdata : None
The text was updated successfully, but these errors were encountered: