Skip to content

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

Merged
merged 2 commits into from
Apr 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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'``.
Copy link
Member

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

Copy link
Member

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'

Copy link
Member Author

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

fold : {0, 1}, default None, keyword-only
Due to daylight saving time, one wall clock time can occur twice
when shifting from summer to winter time; fold describes whether the
Expand Down