Skip to content

BUG #34621 added nanosecond support to class Period #34720

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
wants to merge 7 commits into from
Closed
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
10 changes: 9 additions & 1 deletion pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2355,6 +2355,7 @@ class Period(_Period):

if freq is not None:
freq = cls._maybe_convert_freq(freq)
nanosecond = 0

if ordinal is not None and value is not None:
raise ValueError("Only value or ordinal but not both should be "
Expand Down Expand Up @@ -2404,6 +2405,13 @@ class Period(_Period):
value = str(value)
value = value.upper()
dt, reso = parse_time_string(value, freq)
try:
ts = Timestamp(value, freq=freq)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't pass freq

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new PR is ready (waiting for the question about else)

nanosecond = ts.nanosecond
if nanosecond != 0:
reso = 'nanosecond'
except:
pass
if dt is NaT:
ordinal = NPY_NAT

Expand Down Expand Up @@ -2435,7 +2443,7 @@ class Period(_Period):
base = freq_to_dtype_code(freq)
ordinal = period_ordinal(dt.year, dt.month, dt.day,
dt.hour, dt.minute, dt.second,
dt.microsecond, 0, base)
dt.microsecond, nanosecond, base)

return cls._from_ordinal(ordinal, freq)

Expand Down