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: diff method incorrect on datetime64[s] #59650

Open
3 tasks done
namiyousef opened this issue Aug 29, 2024 · 1 comment
Open
3 tasks done

BUG: diff method incorrect on datetime64[s] #59650

namiyousef opened this issue Aug 29, 2024 · 1 comment
Labels
Bug Closing Candidate May be closeable, needs more eyeballs Datetime Datetime data dtype Needs Info Clarification about behavior needed to assess issue Transformations e.g. cumsum, diff, rank

Comments

@namiyousef
Copy link

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

import pandas as pd

df = pd.DataFrame({"date": ['2022-01-01', '2023-01-01']}).astype({"date": "datetime64[ns]"})
print(df.date.diff())


df = pd.DataFrame({"date": ['2022-01-01', '2023-01-01']}).astype({"date": "datetime64[s]"})
print(df.date.diff())

Issue Description

I'm expecting the difference to be 365 days on both, however on the second example the difference ends up coming in nanoseconds as opposed to seconds.

Expected Behavior

Expecting the diff to be 365 days on both

Installed Versions

Replace this line with the output of pd.show_versions()

@namiyousef namiyousef added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 29, 2024
@asishm
Copy link
Contributor

asishm commented Aug 29, 2024

Thanks for the report. Can you show the output you are currently seeing (and also provide the installed versions in the section)?

On main and latest version 2.2.2, I get

0        NaT
1   365 days
Name: date, dtype: timedelta64[ns]
0        NaT
1   365 days
Name: date, dtype: timedelta64[s]

@rhshadrach rhshadrach added Needs Info Clarification about behavior needed to assess issue Closing Candidate May be closeable, needs more eyeballs Datetime Datetime data dtype Transformations e.g. cumsum, diff, rank and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Closing Candidate May be closeable, needs more eyeballs Datetime Datetime data dtype Needs Info Clarification about behavior needed to assess issue Transformations e.g. cumsum, diff, rank
Projects
None yet
Development

No branches or pull requests

3 participants