@@ -1393,17 +1393,21 @@ def check_for_ordered(self, op):
1393
1393
def _values_for_argsort (self ):
1394
1394
return self ._codes .copy ()
1395
1395
1396
- def argsort (self , ascending = True , kind = 'quicksort' , * args , ** kwargs ):
1397
- """
1398
- Returns the indices that would sort the Categorical instance if
1399
- 'sort_values' was called. This function is implemented to provide
1400
- compatibility with numpy ndarray objects .
1396
+ def argsort (self , * args , ** kwargs ):
1397
+ # TODO(PY2): use correct signature
1398
+ # We have to do *args, **kwargs to avoid a a py2-only signature
1399
+ # issue since np.argsort differs from argsort.
1400
+ """Return the indicies that would sort the Categorical .
1401
1401
1402
- While an ordering is applied to the category values, arg-sorting
1403
- in this context refers more to organizing and grouping together
1404
- based on matching category values. Thus, this function can be
1405
- called on an unordered Categorical instance unlike the functions
1406
- 'Categorical.min' and 'Categorical.max'.
1402
+ Parameters
1403
+ ----------
1404
+ ascending : bool, default True
1405
+ Whether the indices should result in an ascending
1406
+ or descending sort.
1407
+ kind : {'quicksort', 'mergesort', 'heapsort'}, optional
1408
+ Sorting algorithm.
1409
+ args, kwargs:
1410
+ passed through to :func:`numpy.argsort`.
1407
1411
1408
1412
Returns
1409
1413
-------
@@ -1412,10 +1416,28 @@ def argsort(self, ascending=True, kind='quicksort', *args, **kwargs):
1412
1416
See also
1413
1417
--------
1414
1418
numpy.ndarray.argsort
1419
+
1420
+ Notes
1421
+ -----
1422
+ While an ordering is applied to the category values, arg-sorting
1423
+ in this context refers more to organizing and grouping together
1424
+ based on matching category values. Thus, this function can be
1425
+ called on an unordered Categorical instance unlike the functions
1426
+ 'Categorical.min' and 'Categorical.max'.
1427
+
1428
+ Examples
1429
+ --------
1430
+ >>> pd.Categorical(['b', 'b', 'a', 'c']).argsort()
1431
+ array([2, 0, 1, 3])
1432
+
1433
+ >>> cat = pd.Categorical(['b', 'b', 'a', 'c'],
1434
+ ... categories=['c', 'b', 'a'],
1435
+ ... ordered=True)
1436
+ >>> cat.argsort()
1437
+ array([3, 0, 1, 2])
1415
1438
"""
1416
1439
# Keep the implementation here just for the docstring.
1417
- return super (Categorical , self ).argsort (ascending = ascending , kind = kind ,
1418
- * args , ** kwargs )
1440
+ return super (Categorical , self ).argsort (* args , ** kwargs )
1419
1441
1420
1442
def sort_values (self , inplace = False , ascending = True , na_position = 'last' ):
1421
1443
""" Sorts the Categorical by category value returning a new
0 commit comments