-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
PERF: Speed up Period construction #50149
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 3 commits
a2c7f88
942034f
4c351ad
a2a31c6
5df970c
5e1caf0
ec64579
29c3e80
dafa549
6b9eb3e
f8a85a7
c18b3b3
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 | ||
---|---|---|---|---|
|
@@ -421,6 +421,10 @@ cdef parse_datetime_string_with_reso( | |||
parsed = datetime( | ||||
dts.year, dts.month, dts.day, dts.hour, dts.min, dts.sec, dts.us | ||||
) | ||||
if out_bestunit == NPY_DATETIMEUNIT.NPY_FR_ns: | ||||
# No picoseconds, so no nanoseconds. | ||||
# Have to have seen microseconds, in order to have "seen" nanoseconds | ||||
out_bestunit = NPY_DATETIMEUNIT.NPY_FR_us | ||||
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 think doing this will mess up Timestamp inference in a follow-up to #49737 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. Yeah, I only added this block because somehow CI was failing tests only on Linux(maybe a locale problem). pandas/pandas/_libs/tslibs/parsing.pyx Line 413 in 7ef6a71
IMO, we should be checking 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. Ok, I've updated this block now to checking the bestunit. @jbrockmendel @WillAyd Would this work fine? |
||||
reso = { | ||||
NPY_DATETIMEUNIT.NPY_FR_Y: "year", | ||||
NPY_DATETIMEUNIT.NPY_FR_M: "month", | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2574,16 +2574,15 @@ class Period(_Period): | |
value = str(value) | ||
value = value.upper() | ||
dt, reso = parse_time_string(value, freq) | ||
try: | ||
ts = Timestamp(value) | ||
except ValueError: | ||
nanosecond = 0 | ||
else: | ||
nanosecond = ts.nanosecond | ||
if nanosecond != 0: | ||
reso = "nanosecond" | ||
if reso == "nanosecond": | ||
nanosecond = dt.nanosecond | ||
|
||
if dt is NaT: | ||
ordinal = NPY_NAT | ||
# Doesn't matter what this is, we just need to have it | ||
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. Instead of assigning a random value here would it make more sense to just not have it fail later on? |
||
# so that we don't error in block below. We get converted | ||
# to NaT later on anyways | ||
reso = "nanosecond" | ||
|
||
if freq is None: | ||
try: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this impact the period construction? Feels a bit strange to re-assign this variable