Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Consider the dataframe:
df = pd.DataFrame({'col': [True, False]})
The following code works:
df['col'].diff()
The result is:
0 NaN
1 True
Name: col, dtype: object
However, the code:
df.T.diff(axis=1)
gives the error:
numpy boolean subtract, the `-` operator, is not supported, use the bitwise_xor, the `^` operator, or the logical_xor function instead.
Issue Description
Pandas tries to use subtraction. However, the documentation says:
For boolean dtypes, this uses operator.xor() rather than operator.sub().
See: Axial inconsistency of pandas.diff
Expected Behavior
Instead of the error, the result should be True
.
Installed Versions
INSTALLED VERSIONS
commit : 2e218d1
python : 3.11.2.final.0
python-bits : 64
OS : Linux
OS-release : 6.2.9-200.fc37.x86_64
Version : #1 SMP PREEMPT_DYNAMIC Thu Mar 30 22:31:57 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.utf8
LOCALE : en_US.UTF-8
pandas : 1.5.3
numpy : 1.24.2
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 67.6.0
pip : 23.0.1
Cython : 0.29.33
pytest : 7.2.2
hypothesis : None
...
xlrd : 2.0.1
xlwt : 1.3.0
zstandard : 0.20.0
tzdata : 2022.7