-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: periodarr_to_dt64arr #35171
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
PERF: periodarr_to_dt64arr #35171
Changes from 4 commits
0f3f668
c35b798
96df731
a0ece77
d8e557f
d7e6baf
f76eccf
e265bcd
b625c1b
d81bbb9
de221d6
3fe9e10
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 |
---|---|---|
|
@@ -56,6 +56,7 @@ from pandas._libs.tslibs.ccalendar cimport ( | |
get_days_in_month, | ||
) | ||
from pandas._libs.tslibs.ccalendar cimport c_MONTH_NUMBERS | ||
from pandas._libs.tslibs.conversion import ensure_datetime64ns | ||
|
||
from pandas._libs.tslibs.dtypes cimport ( | ||
PeriodDtypeBase, | ||
|
@@ -937,7 +938,7 @@ cdef inline int month_to_quarter(int month) nogil: | |
|
||
@cython.wraparound(False) | ||
@cython.boundscheck(False) | ||
def periodarr_to_dt64arr(const int64_t[:] periodarr, int freq): | ||
def periodarr_to_dt64arr(periodarr: ndarray, freq: int) -> ndarray: | ||
""" | ||
Convert array to datetime64 values from a set of ordinals corresponding to | ||
periods per period convention. | ||
|
@@ -946,9 +947,26 @@ def periodarr_to_dt64arr(const int64_t[:] periodarr, int freq): | |
int64_t[:] out | ||
Py_ssize_t i, l | ||
|
||
l = len(periodarr) | ||
if freq >= FR_DAY: | ||
if freq == FR_NS: | ||
return periodarr | ||
|
||
if freq == FR_US: | ||
dta = periodarr.view("M8[us]") | ||
elif freq == FR_MS: | ||
dta = periodarr.view("M8[ms]") | ||
elif freq == FR_SEC: | ||
dta = periodarr.view("M8[s]") | ||
elif freq == FR_MIN: | ||
dta = periodarr.view("M8[m]") | ||
elif freq == FR_HR: | ||
dta = periodarr.view("M8[h]") | ||
elif freq == FR_DAY: | ||
dta = periodarr.view("M8[D]") | ||
return ensure_datetime64ns(dta) | ||
|
||
out = np.empty(l, dtype='i8') | ||
l = len(periodarr) | ||
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. can you add a comment on which cases this hits |
||
out = np.empty(l, dtype="i8") | ||
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 could be a nogil loop right? (actually couldn't this entire function)? 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. worth doing this 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. this cant be nogil becuase it calls check_dts_bounds, which may raise |
||
|
||
for i in range(l): | ||
out[i] = period_ordinal_to_dt64(periodarr[i], freq) | ||
|
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.
can you add a comment here that you are short-circuiting for perf