-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
DOC: update the pd.Index.argsort docstring #20232
Conversation
pandas/core/indexes/base.py
Outdated
@@ -2316,16 +2316,31 @@ 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I think the "would sort" is important. Does "Return the order of the indices that would sort the index" sound OK and fit on a line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomAugspurger I think "order of the indices" is a bit strange no? I think it would be either "Return the order of the index" or "Return the indices that would sort the index", but not the combination
pandas/core/indexes/base.py
Outdated
underlying data. | ||
Return the order of the indices. | ||
|
||
We have an object with values and index. Using argsort method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably don't need this section.
pandas/core/indexes/base.py
Outdated
|
||
See also | ||
-------- | ||
numpy.ndarray.argsort | ||
numpy.ndarray.argsort : Returns the indices that would sort this array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Say "similar method for NumPy arrays."
pandas/core/indexes/base.py
Outdated
|
||
Examples | ||
-------- | ||
>>> s = pd.Series(data=[4,3,2,1],index=['c','b','a','d']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: spacing after commas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry about the validation script erroring on the args/kwargs
pandas/core/indexes/base.py
Outdated
Return the order of the indices. | ||
|
||
We have an object with values and index. Using argsort method | ||
returns a series of indices that would sort the index. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
series -> array ?
pandas/core/indexes/base.py
Outdated
|
||
Examples | ||
-------- | ||
>>> s = pd.Series(data=[4,3,2,1],index=['c','b','a','d']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can create the Index directly like idx = pd.Index(['c', ..])
and then use that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will make two examples, one with series and one with index.
pandas/core/indexes/base.py
Outdated
|
||
Examples | ||
-------- | ||
>>> s = pd.Series(data=[4,3,2,1], index=['c','b','a','d']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you put spaces between the commas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
pandas/core/indexes/base.py
Outdated
|
||
Parameters | ||
---------- | ||
*args |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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)
pandas/core/indexes/base.py
Outdated
|
||
See also | ||
-------- | ||
numpy.ndarray.argsort | ||
numpy.ndarray.argsort : Similar method for NumPy arrays. |
There was a problem hiding this comment.
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
a1e9329
to
5a183d8
Compare
pandas/core/indexes/base.py
Outdated
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #20232 (comment)
pandas/core/indexes/base.py
Outdated
|
||
Parameters | ||
---------- | ||
*args |
There was a problem hiding this comment.
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)
pandas/core/indexes/base.py
Outdated
|
||
See also | ||
-------- | ||
numpy.ndarray.argsort | ||
numpy.ndarray.argsort : Similar method for NumPy arrays. | ||
pd.Index.sort_values : Return sorted copy of Index |
There was a problem hiding this comment.
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.
pandas/core/indexes/base.py
Outdated
>>> 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 |
There was a problem hiding this comment.
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.
Thanks @dajcs! |
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks:
If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.
We did our best to explain *args and **kwargs
Checklist for other PRs (remove this part if you are doing a PR for the pandas documentation sprint):
git diff upstream/master -u -- "*.py" | flake8 --diff