Skip to content

REF: de-duplicate sort_values #36301

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 1 commit into from
Sep 12, 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
8 changes: 5 additions & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4444,8 +4444,8 @@ def asof_locs(self, where, mask):

def sort_values(
self,
return_indexer=False,
ascending=True,
return_indexer: bool = False,
ascending: bool = True,
na_position: str_t = "last",
key: Optional[Callable] = None,
):
Expand Down Expand Up @@ -4509,7 +4509,9 @@ def sort_values(

# GH 35584. Sort missing values according to na_position kwarg
# ignore na_position for MutiIndex
if not isinstance(self, ABCMultiIndex):
if not isinstance(
self, (ABCMultiIndex, ABCDatetimeIndex, ABCTimedeltaIndex, ABCPeriodIndex)
):
_as = nargsort(
items=idx, ascending=ascending, na_position=na_position, key=key
)
Expand Down
17 changes: 0 additions & 17 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
)
from pandas.core.indexes.numeric import Int64Index
from pandas.core.ops import get_op_result_name
from pandas.core.sorting import ensure_key_mapped
from pandas.core.tools.timedeltas import to_timedelta

_index_doc_kwargs = dict(ibase._index_doc_kwargs)
Expand Down Expand Up @@ -164,22 +163,6 @@ def __contains__(self, key: Any) -> bool:
is_scalar(res) or isinstance(res, slice) or (is_list_like(res) and len(res))
)

def sort_values(self, return_indexer=False, ascending=True, key=None):
"""
Return sorted copy of Index.
"""
idx = ensure_key_mapped(self, key)

_as = idx.argsort()
if not ascending:
_as = _as[::-1]
sorted_index = self.take(_as)

if return_indexer:
return sorted_index, _as
else:
return sorted_index

@Appender(_index_shared_docs["take"] % _index_doc_kwargs)
def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):
nv.validate_take(tuple(), kwargs)
Expand Down