Skip to content

Commit 10bee10

Browse files
authored
PERF: IntervalArray.argsort (#37971)
1 parent 347a7bc commit 10bee10

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pandas/core/arrays/interval.py

+18
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,24 @@ def __lt__(self, other):
619619
def __le__(self, other):
620620
return self._cmp_method(other, operator.le)
621621

622+
def argsort(
623+
self,
624+
ascending: bool = True,
625+
kind: str = "quicksort",
626+
na_position: str = "last",
627+
*args,
628+
**kwargs,
629+
) -> np.ndarray:
630+
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)
631+
632+
if ascending and kind == "quicksort" and na_position == "last":
633+
return np.lexsort((self.right, self.left))
634+
635+
# TODO: other cases we can use lexsort for? much more performant.
636+
return super().argsort(
637+
ascending=ascending, kind=kind, na_position=na_position, **kwargs
638+
)
639+
622640
def fillna(self, value=None, method=None, limit=None):
623641
"""
624642
Fill NA/NaN values using the specified method.

pandas/core/indexes/interval.py

-5
Original file line numberDiff line numberDiff line change
@@ -955,11 +955,6 @@ def _format_space(self) -> str:
955955
space = " " * (len(type(self).__name__) + 1)
956956
return f"\n{space}"
957957

958-
# --------------------------------------------------------------------
959-
960-
def argsort(self, *args, **kwargs) -> np.ndarray:
961-
return np.lexsort((self.right, self.left))
962-
963958
# --------------------------------------------------------------------
964959
# Set Operations
965960

0 commit comments

Comments
 (0)