Skip to content

BUG: strftime can give incorrect answers #46851

Open
@phil20686

Description

@phil20686

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

t1 = pd.Timestamp(year=2000,  month=12, day=25, nanosecond=123456)
t1.strftime(%S.%f) # gives "00.000000"
t2 = pd.Timestamp(year=2000,  month=12, day=25, microsecond=123, nanosecond=456)
t2.strftime(%S.%f) # gives "00.000123"
t1 == t2 # correctly yields true

Issue Description

It is valid to enter a number of nanoseconds that is greater than 1000, but the constructor does not convert this to microseconds, so when strftime is called it seems to take only the value of the microsecond property.

Expected Behavior

It is expected that t1 and t2 should always give the same strftime in all cases. Note that microsecond errors if given a number over 999999 and I think the behaviour of erroring when given a nanosecond over 999 would be fine, and guarantee correct behaviour.

Installed Versions

For some reason this failed with an assertion error, but I do not think that is relevant to this report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugConstructorsSeries/DataFrame/Index/pd.array ConstructorsTimestamppd.Timestamp and associated methods

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions