-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REF: re-use existing conversion functions #34625
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -763,10 +763,9 @@ cdef int64_t get_period_ordinal(npy_datetimestruct *dts, int freq) nogil: | |
period_ordinal : int64_t | ||
""" | ||
cdef: | ||
int64_t unix_date, seconds, delta | ||
int64_t weeks | ||
int64_t day_adj | ||
int64_t unix_date | ||
int freq_group, fmonth, mdiff | ||
NPY_DATETIMEUNIT unit | ||
|
||
freq_group = get_freq_group(freq) | ||
|
||
|
@@ -789,44 +788,42 @@ cdef int64_t get_period_ordinal(npy_datetimestruct *dts, int freq) nogil: | |
mdiff = dts.month - fmonth + 12 | ||
return (dts.year - 1970) * 4 + (mdiff - 1) // 3 | ||
|
||
elif freq == FR_MTH: | ||
return (dts.year - 1970) * 12 + dts.month - 1 | ||
|
||
unix_date = npy_datetimestruct_to_datetime(NPY_FR_D, dts) | ||
|
||
if freq >= FR_SEC: | ||
seconds = unix_date * 86400 + dts.hour * 3600 + dts.min * 60 + dts.sec | ||
|
||
if freq == FR_MS: | ||
return seconds * 1000 + dts.us // 1000 | ||
|
||
elif freq == FR_US: | ||
return seconds * 1000000 + dts.us | ||
|
||
elif freq == FR_NS: | ||
return (seconds * 1000000000 + | ||
dts.us * 1000 + dts.ps // 1000) | ||
|
||
else: | ||
return seconds | ||
|
||
elif freq == FR_MIN: | ||
return unix_date * 1440 + dts.hour * 60 + dts.min | ||
|
||
elif freq == FR_HR: | ||
return unix_date * 24 + dts.hour | ||
|
||
elif freq == FR_DAY: | ||
return unix_date | ||
|
||
elif freq == FR_UND: | ||
return unix_date | ||
elif freq_group == FR_WK: | ||
unix_date = npy_datetimestruct_to_datetime(NPY_FR_D, dts) | ||
return unix_date_to_week(unix_date, freq - FR_WK) | ||
|
||
elif freq == FR_BUS: | ||
unix_date = npy_datetimestruct_to_datetime(NPY_FR_D, dts) | ||
return DtoB(dts, 0, unix_date) | ||
|
||
elif freq_group == FR_WK: | ||
return unix_date_to_week(unix_date, freq - FR_WK) | ||
unit = get_unit(freq) | ||
return npy_datetimestruct_to_datetime(unit, dts) | ||
|
||
|
||
cdef NPY_DATETIMEUNIT get_unit(int freq) nogil: | ||
""" | ||
Convert the freq to the corresponding NPY_DATETIMEUNIT to pass | ||
to npy_datetimestruct_to_datetime. | ||
""" | ||
if freq == FR_MTH: | ||
return NPY_DATETIMEUNIT.NPY_FR_M | ||
if freq == FR_DAY: | ||
return NPY_DATETIMEUNIT.NPY_FR_D | ||
if freq == FR_HR: | ||
return NPY_DATETIMEUNIT.NPY_FR_h | ||
if freq == FR_MIN: | ||
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 do elif 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. updated+green |
||
return NPY_DATETIMEUNIT.NPY_FR_m | ||
if freq == FR_SEC: | ||
return NPY_DATETIMEUNIT.NPY_FR_s | ||
if freq == FR_MS: | ||
return NPY_DATETIMEUNIT.NPY_FR_ms | ||
if freq == FR_US: | ||
return NPY_DATETIMEUNIT.NPY_FR_us | ||
if freq == FR_NS: | ||
return NPY_DATETIMEUNIT.NPY_FR_ns | ||
if freq == FR_UND: | ||
# Default to Day | ||
return NPY_DATETIMEUNIT.NPY_FR_D | ||
|
||
|
||
cdef void get_date_info(int64_t ordinal, int freq, npy_datetimestruct *dts) nogil: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This could alternately just be an enum right? OK as is just suggesting as possible easier solution
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.
I think what you're suggesting is something like:
LMK if you have something else in mind.
The trouble with that is that we currently actually use the values for FR_FOO directly, and this would change those.
There are a bunch of near-duplicate enum-like codes floating around that i do want to de-duplicate. #34588 makes FreqGroup an enum, and after #34587 im hoping we can de-duplicate FreqGroup with Resolution.