-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: de-duplicate code in libparsing/libperiod #38915
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 1 commit
Commits
Show all changes
3 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
cpdef str get_rule_month(str source) | ||
cpdef quarter_to_myear(int year, int quarter, str freq) |
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
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 |
---|---|---|
|
@@ -74,8 +74,7 @@ from pandas._libs.tslibs.dtypes cimport ( | |
PeriodDtypeBase, | ||
attrname_to_abbrevs, | ||
) | ||
from pandas._libs.tslibs.parsing cimport get_rule_month | ||
|
||
from pandas._libs.tslibs.parsing cimport quarter_to_myear | ||
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. prob can cimport parse_time_string too 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. its not cpdef |
||
from pandas._libs.tslibs.parsing import parse_time_string | ||
|
||
from pandas._libs.tslibs.nattype cimport ( | ||
|
@@ -2461,40 +2460,6 @@ cdef int64_t _ordinal_from_fields(int year, int month, quarter, int day, | |
minute, second, 0, 0, base) | ||
|
||
|
||
def quarter_to_myear(year: int, quarter: int, freqstr: str): | ||
""" | ||
A quarterly frequency defines a "year" which may not coincide with | ||
the calendar-year. Find the calendar-year and calendar-month associated | ||
with the given year and quarter under the `freq`-derived calendar. | ||
|
||
Parameters | ||
---------- | ||
year : int | ||
quarter : int | ||
freqstr : str | ||
Equivalent to freq.freqstr | ||
|
||
Returns | ||
------- | ||
year : int | ||
month : int | ||
|
||
See Also | ||
-------- | ||
Period.qyear | ||
""" | ||
if quarter <= 0 or quarter > 4: | ||
raise ValueError('Quarter must be 1 <= q <= 4') | ||
|
||
mnum = c_MONTH_NUMBERS[get_rule_month(freqstr)] + 1 | ||
month = (mnum + (quarter - 1) * 3) % 12 + 1 | ||
if month > mnum: | ||
year -= 1 | ||
|
||
return year, month | ||
# TODO: This whole func is really similar to parsing.pyx L434-L450 | ||
|
||
|
||
def validate_end_alias(how): | ||
how_dict = {'S': 'S', 'E': 'E', | ||
'START': 'S', 'FINISH': 'E', | ||
|
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
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.
prob can remove the comment now :->
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.
updated