-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF/PERF: PeriodDtype decouple from DateOffset #34499
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
jorisvandenbossche
merged 11 commits into
pandas-dev:master
from
jbrockmendel:ref-period_dtype
Jun 4, 2020
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b9e11a6
ENH: implement tslibs.dtypes
jbrockmendel b79165f
unrelated docstring fix
jbrockmendel c0a2751
PERF: define period_dtype_code on all pertinent offsets
jbrockmendel 5ff1766
optimize constructor
jbrockmendel 5ee836a
privatize
jbrockmendel 1d997ec
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel 96346c6
absolute import
jbrockmendel 7bd0d86
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel c45246e
PeriodDtype -> PeriodPseudoDtype
jbrockmendel 702f91f
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel bfac820
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
cdef enum PeriodDtypeCode: | ||
# Annual freqs with various fiscal year ends. | ||
# eg, 2005 for A_FEB runs Mar 1, 2004 to Feb 28, 2005 | ||
A = 1000 # Default alias | ||
A_DEC = 1000 # Annual - December year end | ||
A_JAN = 1001 # Annual - January year end | ||
A_FEB = 1002 # Annual - February year end | ||
A_MAR = 1003 # Annual - March year end | ||
A_APR = 1004 # Annual - April year end | ||
A_MAY = 1005 # Annual - May year end | ||
A_JUN = 1006 # Annual - June year end | ||
A_JUL = 1007 # Annual - July year end | ||
A_AUG = 1008 # Annual - August year end | ||
A_SEP = 1009 # Annual - September year end | ||
A_OCT = 1010 # Annual - October year end | ||
A_NOV = 1011 # Annual - November year end | ||
|
||
# Quarterly frequencies with various fiscal year ends. | ||
# eg, Q42005 for Q_OCT runs Aug 1, 2005 to Oct 31, 2005 | ||
Q_DEC = 2000 # Quarterly - December year end | ||
Q_JAN = 2001 # Quarterly - January year end | ||
Q_FEB = 2002 # Quarterly - February year end | ||
Q_MAR = 2003 # Quarterly - March year end | ||
Q_APR = 2004 # Quarterly - April year end | ||
Q_MAY = 2005 # Quarterly - May year end | ||
Q_JUN = 2006 # Quarterly - June year end | ||
Q_JUL = 2007 # Quarterly - July year end | ||
Q_AUG = 2008 # Quarterly - August year end | ||
Q_SEP = 2009 # Quarterly - September year end | ||
Q_OCT = 2010 # Quarterly - October year end | ||
Q_NOV = 2011 # Quarterly - November year end | ||
|
||
M = 3000 # Monthly | ||
|
||
W_SUN = 4000 # Weekly - Sunday end of week | ||
W_MON = 4001 # Weekly - Monday end of week | ||
W_TUE = 4002 # Weekly - Tuesday end of week | ||
W_WED = 4003 # Weekly - Wednesday end of week | ||
W_THU = 4004 # Weekly - Thursday end of week | ||
W_FRI = 4005 # Weekly - Friday end of week | ||
W_SAT = 4006 # Weekly - Saturday end of week | ||
|
||
B = 5000 # Business days | ||
D = 6000 # Daily | ||
H = 7000 # Hourly | ||
T = 8000 # Minutely | ||
S = 9000 # Secondly | ||
L = 10000 # Millisecondly | ||
U = 11000 # Microsecondly | ||
N = 12000 # Nanosecondly | ||
|
||
|
||
cdef class PeriodPseudoDtype: | ||
cdef readonly: | ||
PeriodDtypeCode dtype_code |
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# period frequency constants corresponding to scikits timeseries | ||
# originals | ||
|
||
|
||
cdef class PeriodPseudoDtype: | ||
""" | ||
Similar to an actual dtype, this contains all of the information | ||
describing a PeriodDtype in an integer code. | ||
""" | ||
# cdef readonly: | ||
# PeriodDtypeCode dtype_code | ||
|
||
def __cinit__(self, PeriodDtypeCode code): | ||
self.dtype_code = code | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, PeriodPseudoDtype): | ||
return False | ||
if not isinstance(self, PeriodPseudoDtype): | ||
# cython semantics, this is a reversed op | ||
return False | ||
return self.dtype_code == other.dtype_code | ||
|
||
@property | ||
def date_offset(self): | ||
""" | ||
Corresponding DateOffset object. | ||
|
||
This mapping is mainly for backward-compatibility. | ||
""" | ||
from .offsets import to_offset | ||
|
||
freqstr = _reverse_period_code_map.get(self.dtype_code) | ||
# equiv: freqstr = libfrequencies.get_freq_str(self.dtype_code) | ||
|
||
return to_offset(freqstr) | ||
|
||
@classmethod | ||
def from_date_offset(cls, offset): | ||
code = offset._period_dtype_code | ||
return cls(code) | ||
|
||
|
||
_period_code_map = { | ||
# Annual freqs with various fiscal year ends. | ||
# eg, 2005 for A-FEB runs Mar 1, 2004 to Feb 28, 2005 | ||
"A-DEC": 1000, # Annual - December year end | ||
"A-JAN": 1001, # Annual - January year end | ||
"A-FEB": 1002, # Annual - February year end | ||
"A-MAR": 1003, # Annual - March year end | ||
"A-APR": 1004, # Annual - April year end | ||
"A-MAY": 1005, # Annual - May year end | ||
"A-JUN": 1006, # Annual - June year end | ||
"A-JUL": 1007, # Annual - July year end | ||
"A-AUG": 1008, # Annual - August year end | ||
"A-SEP": 1009, # Annual - September year end | ||
"A-OCT": 1010, # Annual - October year end | ||
"A-NOV": 1011, # Annual - November year end | ||
|
||
# Quarterly frequencies with various fiscal year ends. | ||
# eg, Q42005 for Q-OCT runs Aug 1, 2005 to Oct 31, 2005 | ||
"Q-DEC": 2000, # Quarterly - December year end | ||
"Q-JAN": 2001, # Quarterly - January year end | ||
"Q-FEB": 2002, # Quarterly - February year end | ||
"Q-MAR": 2003, # Quarterly - March year end | ||
"Q-APR": 2004, # Quarterly - April year end | ||
"Q-MAY": 2005, # Quarterly - May year end | ||
"Q-JUN": 2006, # Quarterly - June year end | ||
"Q-JUL": 2007, # Quarterly - July year end | ||
"Q-AUG": 2008, # Quarterly - August year end | ||
"Q-SEP": 2009, # Quarterly - September year end | ||
"Q-OCT": 2010, # Quarterly - October year end | ||
"Q-NOV": 2011, # Quarterly - November year end | ||
|
||
"M": 3000, # Monthly | ||
|
||
"W-SUN": 4000, # Weekly - Sunday end of week | ||
"W-MON": 4001, # Weekly - Monday end of week | ||
"W-TUE": 4002, # Weekly - Tuesday end of week | ||
"W-WED": 4003, # Weekly - Wednesday end of week | ||
"W-THU": 4004, # Weekly - Thursday end of week | ||
"W-FRI": 4005, # Weekly - Friday end of week | ||
"W-SAT": 4006, # Weekly - Saturday end of week | ||
|
||
"B": 5000, # Business days | ||
"D": 6000, # Daily | ||
"H": 7000, # Hourly | ||
"T": 8000, # Minutely | ||
"S": 9000, # Secondly | ||
"L": 10000, # Millisecondly | ||
"U": 11000, # Microsecondly | ||
"N": 12000, # Nanosecondly | ||
} | ||
|
||
_reverse_period_code_map = { | ||
_period_code_map[key]: key for key in _period_code_map} | ||
|
||
# Yearly aliases; careful not to put these in _reverse_period_code_map | ||
_period_code_map.update({"Y" + key[1:]: _period_code_map[key] | ||
for key in _period_code_map | ||
if key.startswith("A-")}) | ||
|
||
_period_code_map.update({ | ||
"Q": 2000, # Quarterly - December year end (default quarterly) | ||
"A": 1000, # Annual | ||
"W": 4000, # Weekly | ||
"C": 5000, # Custom Business Day | ||
}) |
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
Oops, something went wrong.
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.
Can you add a docstring explaining for what / where this is used?