Skip to content

Commit 91a7c7e

Browse files
author
OlivierLuG
committed
BUG pandas-dev#34621 added nanosecond support to class Period
1 parent 08febd2 commit 91a7c7e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pandas/_libs/tslibs/period.pyx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2355,6 +2355,7 @@ class Period(_Period):
23552355

23562356
if freq is not None:
23572357
freq = cls._maybe_convert_freq(freq)
2358+
nanosecond = 0
23582359

23592360
if ordinal is not None and value is not None:
23602361
raise ValueError("Only value or ordinal but not both should be "
@@ -2404,6 +2405,13 @@ class Period(_Period):
24042405
value = str(value)
24052406
value = value.upper()
24062407
dt, reso = parse_time_string(value, freq)
2408+
try:
2409+
ts = Timestamp(value, freq=freq)
2410+
nanosecond = ts.nanosecond
2411+
if nanosecond != 0:
2412+
reso = 'nanosecond'
2413+
except:
2414+
pass
24072415
if dt is NaT:
24082416
ordinal = NPY_NAT
24092417

@@ -2435,7 +2443,7 @@ class Period(_Period):
24352443
base = freq_to_dtype_code(freq)
24362444
ordinal = period_ordinal(dt.year, dt.month, dt.day,
24372445
dt.hour, dt.minute, dt.second,
2438-
dt.microsecond, 0, base)
2446+
dt.microsecond, nanosecond, base)
24392447

24402448
return cls._from_ordinal(ordinal, freq)
24412449

0 commit comments

Comments
 (0)