-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: update the pandas.Series.sort_index docstring #20248
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 pandas.Series.sort_index docstring #20248
Conversation
Hello @dsakuma! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on March 12, 2018 at 16:59 Hours UTC |
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.
Looking good
pandas/core/series.py
Outdated
|
||
Returns | ||
------- | ||
sorted_obj : Series |
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.
Return values don't need names unless with tuples. Also missing description.
pandas/core/series.py
Outdated
|
||
>>> import numpy as np | ||
>>> arrays = [np.array(['qux', 'qux', 'foo', 'foo',\ | ||
'baz', 'baz', 'bar', 'bar']), |
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.
Bad indentation.
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.
lgtm. very minor change. ping when pushed.
pandas/core/series.py
Outdated
|
||
Specify index level to sort | ||
|
||
>>> import numpy as np |
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 numpy import
pandas/core/series.py
Outdated
|
||
See Also | ||
-------- | ||
sort_values : Sort by the value |
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 add DataFrame.sort_index, DataFrame.sort_values
pandas/core/series.py
Outdated
|
||
See Also | ||
-------- | ||
sort_values : Sort by the value |
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.
make this Series.sort_values
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.
Thanks for the PR! Added some more comments
pandas/core/series.py
Outdated
def sort_index(self, axis=0, level=None, ascending=True, inplace=False, | ||
kind='quicksort', na_position='last', sort_remaining=True): | ||
""" | ||
Sort object by labels. |
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.
"Sort object by labels." -> "Sort Series by index labels." (if we make the docstring specific for Series and not share it with DataFrame, we can make it more specific)
pandas/core/series.py
Outdated
Parameters | ||
---------- | ||
axis : int, default 0 | ||
Axis to direct sorting. |
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 mention this can only be 0 for Series ?
pandas/core/series.py
Outdated
---------- | ||
axis : int, default 0 | ||
Axis to direct sorting. | ||
level : int, default None |
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.
" default None" -> "optional"
pandas/core/series.py
Outdated
Axis to direct sorting. | ||
level : int, default None | ||
If not None, sort on values in specified index level(s). | ||
ascending : boolean, default true |
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.
boolean -> bool (consistent with keyword below)
pandas/core/series.py
Outdated
inplace : bool, default False | ||
If True, perform operation in-place. | ||
kind : {'quicksort', 'mergesort', 'heapsort'}, default 'quicksort' | ||
Choice of sorting algorithm. See also ndarray.np.sort for more |
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.
"ndarray.np.sort" -> "numpy.sort"
(or even better to link to the docs: :func:`numpy.sort`
)
pandas/core/series.py
Outdated
If True, perform operation in-place. | ||
kind : {'quicksort', 'mergesort', 'heapsort'}, default 'quicksort' | ||
Choice of sorting algorithm. See also ndarray.np.sort for more | ||
information. `mergesort` is the only stable algorithm. For |
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.
you can use normal quotes in this case (like 'mergesort'
) to indicate it is a string
pandas/core/series.py
Outdated
DataFrames, this option is only applied when sorting on a single | ||
column or label. | ||
na_position : {'first', 'last'}, default 'last' | ||
If `first` puts NaNs at the beginning, `last` puts NaNs at the end. |
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.
same here (using normal quotes instead of backticks around first and last)
pandas/core/series.py
Outdated
|
||
Examples | ||
-------- | ||
>>> s = pd.Series(['a', 'b', 'c', 'd'], index=[3,2,1,4]) |
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.
spaces after comma (PEP8)
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.
Added some more comments on the examples. We are getting there!
pandas/core/series.py
Outdated
|
||
Examples | ||
-------- | ||
>>> s = pd.Series(['a','b','c','d'], index=[3,2,1,4]) |
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 add spaces after the comma for PEP8 in all examples?
Maybe my previous comment was unclear, but the ['a', 'b', 'c', 'd'],
was already good, but commented for adding spaces in [3,2,1,4]
pandas/core/series.py
Outdated
DataFrames, this option is only applied when sorting on a single | ||
column or label. | ||
na_position : {'first', 'last'}, default 'last' | ||
If `first` puts NaNs at the beginning, 'last' puts NaNs at the end. |
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.
'first' also with normal single quotes
pandas/core/series.py
Outdated
|
||
Sort Descending | ||
|
||
>>> s = pd.Series(['a','b','c','d'], index=[3,2,1,4]) |
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.
You don't need to re-define the series, the examples are run in the same process, so it still knows the s
from the previous one. So this full lines can be removed.
pandas/core/series.py
Outdated
|
||
Sort Inplace | ||
|
||
>>> s = pd.Series(['a','b','c','d'], index=[3,2,1,4]) |
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.
same here
pandas/core/series.py
Outdated
|
||
Sort placing NaNs at first | ||
|
||
>>> s = pd.Series(['a','b','c','d'], index=[3,2,1,np.nan]) |
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.
this one is fine to keep since it is a different series (but same comment regarding PEP8)
pandas/core/series.py
Outdated
4 d | ||
dtype: object | ||
|
||
Sort placing NaNs at first |
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 change "Sort placing NaNs at first" in "By default NaNs are put at the end, but use na_position
to place them at the beginning"
pandas/core/series.py
Outdated
... 'baz','baz','bar','bar']), | ||
... np.array(['two','one','two','one', | ||
... 'two','one','two','one'])] | ||
>>> s = pd.Series([1,2,3,4,5,6,7,8], index=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.
pep8
pandas/core/series.py
Outdated
... 'baz','baz','bar','bar']), | ||
... np.array(['two','one','two','one', | ||
... 'two','one','two','one'])] | ||
>>> s = pd.Series([1,2,3,4,5,6,7,8], index=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.
Sam here, this does not need to be redefined
@jorisvandenbossche, @jreback and @villasv Thanks for the comments! |
@dsakuma Thanks a lot! |
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: