Skip to content

BUG: strftime can give incorrect answers #46851

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

Open
3 tasks done
phil20686 opened this issue Apr 23, 2022 · 1 comment
Open
3 tasks done

BUG: strftime can give incorrect answers #46851

phil20686 opened this issue Apr 23, 2022 · 1 comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Timestamp pd.Timestamp and associated methods

Comments

@phil20686
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

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.

@phil20686 phil20686 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 23, 2022
@simonjayhawkins
Copy link
Member

Thanks @phil20686 for the report. #29461 looks related (cc @smarie re open PR #46116)

but the constructor does not convert this to microseconds

yep, although the two timestamps compare equal, they are not in a normalized form.

>>> t1 == t2  # correctly yields true
True
>>> 
>>> t1.microsecond, t2.microsecond
(0, 123)
>>> 
>>> t1.nanosecond, t2.nanosecond
(123456, 456)

so will keep this issue open and label as constructor issue.

@simonjayhawkins simonjayhawkins added Constructors Series/DataFrame/Index/pd.array Constructors Timestamp pd.Timestamp and associated methods and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 20, 2022
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone May 20, 2022
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Timestamp pd.Timestamp and associated methods
Projects
None yet
Development

No branches or pull requests

3 participants