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

Conversation

dajcs
Copy link
Contributor

@dajcs dajcs commented Mar 10, 2018

Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):

  • PR title is "DOC: update the docstring"
  • The validation script passes: scripts/validate_docstrings.py <your-function-or-method>
  • The PEP8 style check passes: git diff upstream/master -u -- "*.py" | flake8 --diff
  • The html version looks good: python doc/make.py --single <your-function-or-method>
  • It has been proofread on language by another sprint participant

Please include the output of the validation script below between the "```" ticks:

################################################################################
####################### Docstring (pandas.Index.argsort) #######################
################################################################################

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.

Parameters
----------
*args
    Passed to `numpy.ndarray.argsort`.
**kwargs
    Passed to `numpy.ndarray.argsort`.

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

See also
--------
numpy.ndarray.argsort : Returns the indices that would sort this array.

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

################################################################################
################################## Validation ##################################
################################################################################

Errors found:
        Errors in parameters section
                Parameters {'args', 'kwargs'} not documented
                Unknown parameters {'**kwargs', '*args'}
                Parameter "*args" has no type
                Parameter "**kwargs" has no type

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):

  • closes #xxxx
  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

@@ -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.
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Member

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

underlying data.
Return the order of the indices.

We have an object with values and index. Using argsort method
Copy link
Contributor

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.


See also
--------
numpy.ndarray.argsort
numpy.ndarray.argsort : Returns the indices that would sort this array.
Copy link
Contributor

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."


Examples
--------
>>> s = pd.Series(data=[4,3,2,1],index=['c','b','a','d'])
Copy link
Contributor

Choose a reason for hiding this comment

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

PEP8: spacing after commas.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a 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

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.
Copy link
Member

Choose a reason for hiding this comment

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

series -> array ?


Examples
--------
>>> s = pd.Series(data=[4,3,2,1],index=['c','b','a','d'])
Copy link
Member

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

Copy link
Contributor Author

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.


Examples
--------
>>> s = pd.Series(data=[4,3,2,1], index=['c','b','a','d'])
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


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)


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

@jreback jreback added Docs Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Mar 10, 2018
@dajcs dajcs force-pushed the docstring_index_argsort branch from a1e9329 to 5a183d8 Compare March 10, 2018 21:50
@@ -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.

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


See also
--------
numpy.ndarray.argsort
numpy.ndarray.argsort : Similar method for NumPy arrays.
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.

>>> 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.

@TomAugspurger TomAugspurger merged commit 0ed9916 into pandas-dev:master Mar 12, 2018
@TomAugspurger
Copy link
Contributor

Thanks @dajcs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants