Skip to content

DOC: update the pd.Index.argsort docstring #20232

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 4 commits into from
Mar 12, 2018
Merged
Changes from 1 commit
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
28 changes: 24 additions & 4 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2316,16 +2316,36 @@ def shift(self, periods=1, freq=None):

def argsort(self, *args, **kwargs):
"""
Returns the indices that would sort the index and its
underlying data.
Return the order of the indices that would sort the index.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Parameters
----------
*args
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorisvandenbossche this is the correct format for args/kwargs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was only thinking it might actually make more sense to list the ones that are useful. I think it is only kind ? (axis certainly not, and order not as well?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we do this for Series.argsort now. so should replicate here. or shared these doc-strings (best)

Passed to `numpy.ndarray.argsort`.
**kwargs
Passed to `numpy.ndarray.argsort`.

Returns
-------
argsorted : numpy array
numpy.ndarray
Argsorted indices of the index

See also
--------
numpy.ndarray.argsort
numpy.ndarray.argsort : Similar method for NumPy arrays.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see also Index.sort_values

pd.Index.sort_values : Return sorted copy of Index
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need the pd.


Examples
--------
>>> pd.Index(['b','a','d','c']).argsort()
array([1, 0, 3, 2], dtype=int64)

When applying argsort to a Series object then the result won't
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think from here down is relevant. Series has its own example.

be affected by Series values only by Series index.

>>> s = pd.Series(data=[4, 3, 2, 1], index=['c', 'b', 'a', 'd'])
>>> s.index.argsort()
array([2, 1, 0, 3], dtype=int64)
"""
result = self.asi8
if result is None:
Expand Down