-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Clarify Timestamp(unit=) will not necessarily set unit #52311
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
Conversation
pandas/_libs/tslibs/timestamps.pyx
Outdated
@@ -1293,6 +1293,9 @@ class Timestamp(_Timestamp): | |||
Unit used for conversion if ts_input is of type int or float. The | |||
valid values are 'D', 'h', 'm', 's', 'ms', 'us', and 'ns'. For | |||
example, 's' means seconds and 'ms' means milliseconds. | |||
|
|||
The result will be stored in nanoseconds, and the unit attribute | |||
will be set as ``'ns'``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is only the case for floats. for ints we do keep the unit where possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this as well (haven't checked to see if its expected):
import pandas as pd
unit = "s"
ts1 = pd.to_datetime(1, unit=unit)
ts2 = pd.Timestamp(1, unit=unit)
print(f"{ts1.unit=}, {ts2.unit=}")
td1 = pd.to_timedelta(1, unit=unit)
td2 = pd.Timedelta(1, unit=unit)
print(f"{td1.unit=}, {td2.unit=}")
output:
ts1.unit='ns', ts2.unit='s'
td1.unit='ns', td2.unit='ns'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, clarified that it's only for floats
thx @mroeschke |
…necessarily set unit
…l not necessarily set unit) (#52360) Backport PR #52311: DOC: Clarify Timestamp(unit=) will not necessarily set unit Co-authored-by: Matthew Roeschke <[email protected]>
pd.TimeStamp
&pd.Timedelta
not always adhering tounit
parameter inpandas-2.0
#52286 (Replace xxxx with the GitHub issue number)doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.