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

Conversation

mroeschke
Copy link
Member

@mroeschke mroeschke added Docs Non-Nano datetime64/timedelta64 with non-nanosecond resolution Timestamp pd.Timestamp and associated methods labels Mar 30, 2023
@mroeschke mroeschke added this to the 2.0 milestone Mar 30, 2023
@@ -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

@phofl phofl merged commit a09ea5e into pandas-dev:main Apr 2, 2023
@phofl
Copy link
Member

phofl commented Apr 2, 2023

thx @mroeschke

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Apr 2, 2023
phofl pushed a commit that referenced this pull request Apr 2, 2023
…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]>
@mroeschke mroeschke deleted the doc/ts/unit branch April 2, 2023 18:08
topper-123 pushed a commit to topper-123/pandas that referenced this pull request Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Non-Nano datetime64/timedelta64 with non-nanosecond resolution Timestamp pd.Timestamp and associated methods
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: pd.TimeStamp & pd.Timedelta not always adhering to unit parameter in pandas-2.0
4 participants