Skip to content

Commit d5e8198

Browse files
committed
Back to _values_for_argsort
1 parent 5c758aa commit d5e8198

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

pandas/core/arrays/base.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -237,31 +237,21 @@ def isna(self):
237237
"""
238238
raise AbstractMethodError(self)
239239

240-
def _simple_ndarray(self):
240+
def _values_for_argsort(self):
241241
# type: () -> ndarray
242-
"""Convert the array to a simple ndarray representaiton.
243-
244-
Many methods can operate indirectly on a cheap-to-compute array that
245-
is somehow representative of the extension array. For example, rather
246-
than sorting an ExtensionArray directly, which might be expensive,
247-
we could convert the ExtensionArray to a representative ndarray of
248-
integers, sort the integers, and perform a ``take``.
249-
250-
The coversion between ExtensionArray and the simple ndarray should be
251-
strictly monotonic https://en.wikipedia.org/wiki/Monotonic_function,
252-
and as cheap to compute as possible.
242+
"""Return values for sorting.
253243
254244
Returns
255245
-------
256-
values : ndarray
246+
ndarray
247+
The transformed values should maintain the ordering between values
248+
within the array.
257249
258250
See Also
259251
--------
260252
ExtensionArray.argsort
261253
"""
262-
# Implemnetor note: This method is currently used in
263-
# - ExtensionArray.argsort
264-
254+
# Note: this is used in `ExtensionArray.argsort`.
265255
return np.array(self)
266256

267257
def argsort(self, ascending=True, kind='quicksort', *args, **kwargs):
@@ -289,11 +279,10 @@ def argsort(self, ascending=True, kind='quicksort', *args, **kwargs):
289279
"""
290280
# Implementor note: You have two places to override the behavior of
291281
# argsort.
292-
# 1. _simple_ndarray : construct the values passed to np.argsort
282+
# 1. _values_for_argsort : construct the values passed to np.argsort
293283
# 2. argsort : total control over sorting.
294-
295284
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)
296-
values = self._simple_ndarray()
285+
values = self._values_for_argsort()
297286
result = np.argsort(values, kind=kind, **kwargs)
298287
if not ascending:
299288
result = result[::-1]

pandas/core/arrays/categorical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ def check_for_ordered(self, op):
13781378
"you can use .as_ordered() to change the "
13791379
"Categorical to an ordered one\n".format(op=op))
13801380

1381-
def _simple_ndarray(self):
1381+
def _values_for_argsort(self):
13821382
return self._codes.copy()
13831383

13841384
def argsort(self, *args, **kwargs):

0 commit comments

Comments
 (0)