-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from all commits
91a7c7e
73a6eab
ea9f69c
ab5640f
95d740e
abb0936
8a559cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 " | ||
|
@@ -2404,6 +2405,14 @@ class Period(_Period): | |
value = str(value) | ||
value = value.upper() | ||
dt, reso = parse_time_string(value, freq) | ||
try: | ||
ts = Timestamp(value) | ||
except ValueError: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we end up parsing this twice which is not good, yeah i think this needs to be integrated a bit more to i guess the currently soln would be ok in the interim, but would need to run asv's on all periods to see what kind of perf hit here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far I read, nanosecond was not accepted into dateutil module. This interim solution could stand for a while. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
we don't wait for dateutil in this, as it will not likey every support nanosecond because the standard library does not |
||
nanosecond = 0 | ||
else: | ||
nanosecond = ts.nanosecond | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if nanosecond != 0: | ||
reso = 'nanosecond' | ||
if dt is NaT: | ||
ordinal = NPY_NAT | ||
|
||
|
@@ -2435,7 +2444,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, 1000*nanosecond, base) | ||
|
||
return cls._from_ordinal(ordinal, freq) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -484,6 +484,22 @@ def test_period_cons_combined(self): | |
with pytest.raises(ValueError, match=msg): | ||
Period("2011-01", freq="1D1W") | ||
|
||
@pytest.mark.parametrize("day_", ["1970/01/01 ", "2020-12-31 ", "1981/09/13 "]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont think the trailing underscores are necessary for these names |
||
@pytest.mark.parametrize("hour_", ["00:00:00", "00:00:01", "23:59:59", "12:00:59"]) | ||
@pytest.mark.parametrize( | ||
"floating_sec_, expected", | ||
[ | ||
(".000000001", 1), | ||
(".000000999", 999), | ||
(".123456789", 789), | ||
(".999999999", 999), | ||
], | ||
) | ||
def test_period_constructor_nanosecond(self, day_, hour_, floating_sec_, expected): | ||
# GH 34621 | ||
result = Period(day_ + hour_ + floating_sec_).start_time.nanosecond | ||
assert result == expected | ||
|
||
|
||
class TestPeriodMethods: | ||
def test_round_trip(self): | ||
|
Uh oh!
There was an error while loading. Please reload this page.