Skip to content

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

Open
@namiyousef

Description

@namiyousef

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugClosing CandidateMay be closeable, needs more eyeballsDatetimeDatetime data dtypeNeeds InfoClarification about behavior needed to assess issueTransformationse.g. cumsum, diff, rank

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions