Skip to content

DEPR: Restrict nanosecond range in Timestamp constructor #48538

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

Closed
mroeschke opened this issue Sep 13, 2022 · 2 comments · Fixed by #48691
Closed

DEPR: Restrict nanosecond range in Timestamp constructor #48538

mroeschke opened this issue Sep 13, 2022 · 2 comments · Fixed by #48691
Labels
Datetime Datetime data dtype Deprecate Functionality to remove in pandas

Comments

@mroeschke
Copy link
Member

xref #48255

In the normal datetime.datetime constructor, each component is bounded to [0, next_largest_component) e.g.

In [5]: import datetime

In [6]: datetime.datetime(year=2022, month=1, day=1, microsecond=1000000)
ValueError: microsecond must be in 0..999999

In [7]: Timestamp(year=2022, month=1, day=1, microsecond=1000000)
ValueError: microsecond must be in 0..999999

Since Timestamp supports nanosecond, ideally it should be bounded to [0, microsecond_boundary) but this is not the case

In [10]: Timestamp(year=2022, month=1, day=1, nanosecond=1_000)
Out[10]: Timestamp('2022-01-01 00:00:00.000001000')

In [12]: Timestamp(year=2022, month=1, day=1, nanosecond=1_000_000)
Out[12]: Timestamp('2022-01-01 00:00:00.001000000')

# Explained by GH 48255
In [13]: Timestamp(year=2022, month=1, day=1, nanosecond=1_000_000_000)
Out[13]: Timestamp('2022-01-01 00:00:00.-00727380')

Thoughts @jbrockmendel?

@mroeschke mroeschke added Datetime Datetime data dtype Deprecate Functionality to remove in pandas labels Sep 13, 2022
@jbrockmendel
Copy link
Member

makes sense. microsecond_boundary is 1_000?

@mroeschke
Copy link
Member Author

microsecond_boundary is 1_000?

Correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Deprecate Functionality to remove in pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants