-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Conversation
pandas/_libs/tslibs/period.pyx
Outdated
@@ -1058,18 +1058,20 @@ cdef class _Period(object): | |||
return hash((self.ordinal, self.freqstr)) | |||
|
|||
def _add_delta(self, other): | |||
if isinstance(other, (timedelta, np.timedelta64, offsets.Tick)): | |||
offset = frequencies.to_offset(self.freq.rule_code) | |||
if isinstance(offset, offsets.Tick): |
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 if isinstance(self.freq, offsets.Tick)
.
Codecov Report
@@ Coverage Diff @@
## master #21447 +/- ##
=======================================
Coverage 91.89% 91.89%
=======================================
Files 153 153
Lines 49604 49604
=======================================
Hits 45584 45584
Misses 4020 4020
Continue to review full report at Codecov.
|
@jbrockmendel : |
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.
- @gfyoung comments. (just see if we have an asv, you can run them and run report and significant diffs)
pandas/_libs/tslibs/period.pyx
Outdated
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
can you do this
as isn't showing much (recall it is wonky on my machine for reasons unknown)
|
pandas/_libs/tslibs/period.pyx
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
can you do this
thanks! |
Removes an unnecessary call to
frequencies.to_offset
, one of the last few non-cython dependencies in the file.will post asv results when available.