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

BUG: Axial inconsistency of pandas.diff #52579

Open
2 of 3 tasks
psads-git opened this issue Apr 10, 2023 · 2 comments
Open
2 of 3 tasks

BUG: Axial inconsistency of pandas.diff #52579

psads-git opened this issue Apr 10, 2023 · 2 comments
Assignees
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug

Comments

@psads-git
Copy link

psads-git commented Apr 10, 2023

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

@psads-git psads-git added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 10, 2023
@psads-git psads-git changed the title BUG: BUG: Axial inconsistency of pandas.diff Apr 10, 2023
@topper-123 topper-123 added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 4, 2023
@topper-123
Copy link
Contributor

Yes, this is bug. PRs welcome

@mikejigglypuff
Copy link

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug
Projects
None yet
3 participants