-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
perf improvements in tslibs.period #21447
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 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
36c2ef1
use ccalendar instead of tslib.monthrange, cythonize bits of resolution
jbrockmendel d3eb043
revert _Tick since it breaks pickles
jbrockmendel c1c6279
remove _Tick
jbrockmendel 2f2391f
remove _Tick
jbrockmendel a64a5b4
revert a bit
jbrockmendel 140f149
revert resolution
jbrockmendel 4752e36
remove unnecessary to_offset call
jbrockmendel 3fea745
revert
jbrockmendel 622bed7
fixup wrap long line
jbrockmendel daf9aaf
restore apparently-necessary to_offset call
jbrockmendel 7678a45
Merge branch 'master' of https://github.com/pandas-dev/pandas into cy…
jbrockmendel a3d11c6
implement is_offset_object
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
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 |
---|---|---|
|
@@ -19,7 +19,8 @@ from pandas.compat import PY2 | |
|
||
cimport cython | ||
|
||
from cpython.datetime cimport PyDateTime_Check, PyDateTime_IMPORT | ||
from cpython.datetime cimport (PyDateTime_Check, PyDelta_Check, | ||
PyDateTime_IMPORT) | ||
# import datetime C API | ||
PyDateTime_IMPORT | ||
|
||
|
@@ -1058,18 +1059,21 @@ cdef class _Period(object): | |
return hash((self.ordinal, self.freqstr)) | ||
|
||
def _add_delta(self, other): | ||
if isinstance(other, (timedelta, np.timedelta64, offsets.Tick)): | ||
cdef: | ||
int64_t nanos, offset_nanos | ||
|
||
if (PyDelta_Check(other) or util.is_timedelta64_object(other) or | ||
isinstance(other, offsets.Tick)): | ||
offset = frequencies.to_offset(self.freq.rule_code) | ||
if isinstance(offset, offsets.Tick): | ||
nanos = delta_to_nanoseconds(other) | ||
offset_nanos = delta_to_nanoseconds(offset) | ||
|
||
if nanos % offset_nanos == 0: | ||
ordinal = self.ordinal + (nanos // offset_nanos) | ||
return Period(ordinal=ordinal, freq=self.freq) | ||
msg = 'Input cannot be converted to Period(freq={0})' | ||
raise IncompatibleFrequency(msg.format(self.freqstr)) | ||
elif isinstance(other, offsets.DateOffset): | ||
elif getattr(other, "_typ", None) == "dateoffset": | ||
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. maybe should add an is_offset_object in util.pxd 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 this |
||
freqstr = other.rule_code | ||
base = get_base_alias(freqstr) | ||
if base == self.freq.rule_code: | ||
|
@@ -1082,8 +1086,8 @@ cdef class _Period(object): | |
|
||
def __add__(self, other): | ||
if is_period_object(self): | ||
if isinstance(other, (timedelta, np.timedelta64, | ||
offsets.DateOffset)): | ||
if (PyDelta_Check(other) or util.is_timedelta64_object(other) or | ||
getattr(other, "_typ", None) == "dateoffset"): | ||
return self._add_delta(other) | ||
elif other is NaT: | ||
return NaT | ||
|
@@ -1109,8 +1113,8 @@ cdef class _Period(object): | |
|
||
def __sub__(self, other): | ||
if is_period_object(self): | ||
if isinstance(other, (timedelta, np.timedelta64, | ||
offsets.DateOffset)): | ||
if (PyDelta_Check(other) or util.is_timedelta64_object(other) or | ||
getattr(other, "_typ", None) == "dateoffset"): | ||
neg_other = -other | ||
return self + neg_other | ||
elif util.is_integer_object(other): | ||
|
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 along with the line above is redundant;
isinstance(offset, offsets.Tick)
if and only ifisinstance(self.freq, offsets.Tick)
.