-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
[PERF] Get rid of MultiIndex conversion in IntervalIndex.is_monotonic methods #25820
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
Changes from all commits
7cb99e1
0c54e55
e9f2601
8c5c580
543b0d3
0bba602
ceb91f3
2e6fa28
34ad0f2
57f8404
480b353
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -438,23 +438,23 @@ def is_monotonic(self): | |
Return True if the IntervalIndex is monotonic increasing (only equal or | ||
increasing values), else False | ||
""" | ||
return self._multiindex.is_monotonic | ||
return self.is_monotonic_increasing | ||
|
||
@cache_readonly | ||
def is_monotonic_increasing(self): | ||
""" | ||
Return True if the IntervalIndex is monotonic increasing (only equal or | ||
increasing values), else False | ||
""" | ||
return self._multiindex.is_monotonic_increasing | ||
return self._engine.is_monotonic_increasing | ||
|
||
@cache_readonly | ||
def is_monotonic_decreasing(self): | ||
""" | ||
Return True if the IntervalIndex is monotonic decreasing (only equal or | ||
decreasing values), else False | ||
""" | ||
return self._multiindex.is_monotonic_decreasing | ||
return self[::-1].is_monotonic_increasing | ||
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. I would prefer checking monotonic_decreasing directly, so:
(But adding the properties to 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. I have tried in this way. But
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. You are right, as lexsort does treats equal values as increasing their index location, so is_monotonic(...)[1] will fail. It would still deliver efficiency gains from calculating 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. When implementing
|
||
|
||
@cache_readonly | ||
def is_unique(self): | ||
|
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.
Just note that this measures access speed to the cached value, not the time cost of the underlying operation. To time the underlying method, you need to do
pd.IntervalIndex.is_monotonic_increasing.func(self.intv)
, but that hits a cached value atself.intv._multiindex.is_monotonic_increasing
in master, so will still seem to be in the nanosecond range, but really won't be because it's just the caching doing tricks.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.
You're right. The performance is even better. The
_engine
is set in prior in asv setup method.