Skip to content

Commit 44b6d72

Browse files
committed
Remove _values_for_argsort
1 parent b61fb8d commit 44b6d72

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

pandas/core/arrays/base.py

+2-19
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,8 @@ def isna(self):
217217
"""
218218
raise AbstractMethodError(self)
219219

220-
def _values_for_argsort(self):
221-
# type: () -> ndarray
222-
"""Get the ndarray to be passed to np.argsort.
223-
224-
This is called from within 'ExtensionArray.argsort'.
225-
226-
Returns
227-
-------
228-
values : ndarray
229-
"""
230-
return np.array(self)
231-
232220
def argsort(self, ascending=True, kind='quicksort', *args, **kwargs):
233-
"""Returns the indices that would sort this array.
221+
"""Return the indices that would sort this array.
234222
235223
Parameters
236224
----------
@@ -251,13 +239,8 @@ def argsort(self, ascending=True, kind='quicksort', *args, **kwargs):
251239
--------
252240
numpy.argsort
253241
"""
254-
# Implementor note: You have two places to override the behavior of
255-
# argsort.
256-
# 1. _values_for_argsort : construct the values passed to np.argsort
257-
# 2. argsort : total control over sorting.
258-
259242
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)
260-
values = self._values_for_argsort()
243+
values = self.astype(object)
261244
result = np.argsort(values, kind=kind, **kwargs)
262245
if not ascending:
263246
result = result[::-1]

pandas/core/arrays/categorical.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1386,9 +1386,6 @@ def check_for_ordered(self, op):
13861386
"you can use .as_ordered() to change the "
13871387
"Categorical to an ordered one\n".format(op=op))
13881388

1389-
def _values_for_argsort(self):
1390-
return self._codes.copy()
1391-
13921389
def argsort(self, ascending=True, kind='quicksort', *args, **kwargs):
13931390
"""
13941391
Returns the indices that would sort the Categorical instance if
@@ -1409,9 +1406,11 @@ def argsort(self, ascending=True, kind='quicksort', *args, **kwargs):
14091406
--------
14101407
numpy.ndarray.argsort
14111408
"""
1412-
# Keep the implementation here just for the docstring.
1413-
return super(Categorical, self).argsort(ascending=ascending, kind=kind,
1414-
*args, **kwargs)
1409+
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)
1410+
result = np.argsort(self._codes.copy(), kind=kind, **kwargs)
1411+
if not ascending:
1412+
result = result[::-1]
1413+
return result
14151414

14161415
def sort_values(self, inplace=False, ascending=True, na_position='last'):
14171416
""" Sorts the Categorical by category value returning a new

0 commit comments

Comments
 (0)