Skip to content

PERF: IntervalArray.argsort #37971

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 2 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,24 @@ def __lt__(self, other):
def __le__(self, other):
return self._cmp_method(other, operator.le)

def argsort(
self,
ascending: bool = True,
kind: str = "quicksort",
na_position: str = "last",
*args,
**kwargs,
) -> np.ndarray:
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)

if ascending and kind == "quicksort" and na_position == "last":
return np.lexsort((self.right, self.left))

# TODO: other cases we can use lexsort for? much more performant.
return super().argsort(
ascending=ascending, kind=kind, na_position=na_position, **kwargs
)

def fillna(self, value=None, method=None, limit=None):
"""
Fill NA/NaN values using the specified method.
Expand Down
5 changes: 0 additions & 5 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,6 @@ def _format_space(self) -> str:
space = " " * (len(type(self).__name__) + 1)
return f"\n{space}"

# --------------------------------------------------------------------

def argsort(self, *args, **kwargs) -> np.ndarray:
return np.lexsort((self.right, self.left))

# --------------------------------------------------------------------
# Set Operations

Expand Down