-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
WIP: speed up Period creation #23500
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
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 |
---|---|---|
|
@@ -30,7 +30,7 @@ cdef extern from "src/datetime/np_datetime.h": | |
npy_datetimestruct *d) nogil | ||
|
||
cimport util | ||
from util cimport is_period_object, is_string_object | ||
from util cimport is_period_object, is_string_object, is_offset_object | ||
|
||
from timestamps import Timestamp, maybe_integer_op_deprecated | ||
from timezones cimport is_utc, is_tzlocal, get_dst_info | ||
|
@@ -1442,7 +1442,7 @@ def extract_ordinals(object[:] values, freq): | |
int64_t[:] ordinals = np.empty(n, dtype=np.int64) | ||
object p | ||
|
||
freqstr = Period._maybe_convert_freq(freq).freqstr | ||
freq = Period._maybe_convert_freq(freq) | ||
|
||
for i in range(n): | ||
p = values[i] | ||
|
@@ -1453,8 +1453,8 @@ def extract_ordinals(object[:] values, freq): | |
try: | ||
ordinals[i] = p.ordinal | ||
|
||
if p.freqstr != freqstr: | ||
msg = DIFFERENT_FREQ_INDEX.format(freqstr, p.freqstr) | ||
if p.freqstr != freq.freqstr: | ||
msg = DIFFERENT_FREQ_INDEX.format(freq.freqstr, p.freqstr) | ||
raise IncompatibleFrequency(msg) | ||
|
||
except AttributeError: | ||
|
@@ -1567,12 +1567,12 @@ cdef class _Period(object): | |
|
||
@classmethod | ||
def _maybe_convert_freq(cls, object freq): | ||
if not is_offset_object(freq): | ||
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. This looks fine, and the timings you posted look nice. Can you try adding the 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. Sure, will give that a shot. Will be out for a bit so may be several hours before I can post the results. 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'm not seeing any significant changes from implementing this - did you have a particular benchmark in mind? 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 didn’t have any one in mind, but had a hunch. Thanks for taking a look |
||
if isinstance(freq, (int, tuple)): | ||
code, stride = get_freq_code(freq) | ||
freq = get_freq_str(code, stride) | ||
|
||
if isinstance(freq, (int, tuple)): | ||
code, stride = get_freq_code(freq) | ||
freq = get_freq_str(code, stride) | ||
|
||
freq = to_offset(freq) | ||
freq = to_offset(freq) | ||
|
||
if freq.n <= 0: | ||
raise ValueError('Frequency must be positive, because it' | ||
|
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.
everything here is orthogonal to the rest of the PR, right?
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.
Yeah, this is insignificant from a performance perspective - just related cleanup.