Skip to content

Commit dda1d0f

Browse files
Daniel SaxtonPingviinituutti
Daniel Saxton
authored andcommitted
DOC: Clean sort_values and sort_index docstrings (pandas-dev#24843)
1 parent aae8891 commit dda1d0f

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

pandas/core/generic.py

+28-23
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ def set_axis(self, labels, axis=0, inplace=None):
530530
The axis to update. The value 0 identifies the rows, and 1
531531
identifies the columns.
532532
533-
inplace : boolean, default None
533+
inplace : bool, default None
534534
Whether to return a new %(klass)s instance.
535535
536536
.. warning::
@@ -3966,35 +3966,37 @@ def add_suffix(self, suffix):
39663966
def sort_values(self, by=None, axis=0, ascending=True, inplace=False,
39673967
kind='quicksort', na_position='last'):
39683968
"""
3969-
Sort by the values along either axis
3969+
Sort by the values along either axis.
39703970
39713971
Parameters
39723972
----------%(optional_by)s
39733973
axis : %(axes_single_arg)s, default 0
3974-
Axis to be sorted
3974+
Axis to be sorted.
39753975
ascending : bool or list of bool, default True
39763976
Sort ascending vs. descending. Specify list for multiple sort
39773977
orders. If this is a list of bools, must match the length of
39783978
the by.
39793979
inplace : bool, default False
3980-
if True, perform operation in-place
3980+
If True, perform operation in-place.
39813981
kind : {'quicksort', 'mergesort', 'heapsort'}, default 'quicksort'
39823982
Choice of sorting algorithm. See also ndarray.np.sort for more
39833983
information. `mergesort` is the only stable algorithm. For
39843984
DataFrames, this option is only applied when sorting on a single
39853985
column or label.
39863986
na_position : {'first', 'last'}, default 'last'
3987-
`first` puts NaNs at the beginning, `last` puts NaNs at the end
3987+
Puts NaNs at the beginning if `first`; `last` puts NaNs at the
3988+
end.
39883989
39893990
Returns
39903991
-------
3991-
sorted_obj : %(klass)s
3992+
sorted_obj : DataFrame or None
3993+
DataFrame with sorted values if inplace=False, None otherwise.
39923994
39933995
Examples
39943996
--------
39953997
>>> df = pd.DataFrame({
3996-
... 'col1' : ['A', 'A', 'B', np.nan, 'D', 'C'],
3997-
... 'col2' : [2, 1, 9, 8, 7, 4],
3998+
... 'col1': ['A', 'A', 'B', np.nan, 'D', 'C'],
3999+
... 'col2': [2, 1, 9, 8, 7, 4],
39984000
... 'col3': [0, 1, 9, 4, 2, 3],
39994001
... })
40004002
>>> df
@@ -4056,32 +4058,35 @@ def sort_values(self, by=None, axis=0, ascending=True, inplace=False,
40564058
def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
40574059
kind='quicksort', na_position='last', sort_remaining=True):
40584060
"""
4059-
Sort object by labels (along an axis)
4061+
Sort object by labels (along an axis).
40604062
40614063
Parameters
40624064
----------
4063-
axis : %(axes)s to direct sorting
4065+
axis : {0 or 'index', 1 or 'columns'}, default 0
4066+
The axis along which to sort. The value 0 identifies the rows,
4067+
and 1 identifies the columns.
40644068
level : int or level name or list of ints or list of level names
4065-
if not None, sort on values in specified index level(s)
4066-
ascending : boolean, default True
4067-
Sort ascending vs. descending
4069+
If not None, sort on values in specified index level(s).
4070+
ascending : bool, default True
4071+
Sort ascending vs. descending.
40684072
inplace : bool, default False
4069-
if True, perform operation in-place
4073+
If True, perform operation in-place.
40704074
kind : {'quicksort', 'mergesort', 'heapsort'}, default 'quicksort'
4071-
Choice of sorting algorithm. See also ndarray.np.sort for more
4072-
information. `mergesort` is the only stable algorithm. For
4073-
DataFrames, this option is only applied when sorting on a single
4074-
column or label.
4075+
Choice of sorting algorithm. See also ndarray.np.sort for more
4076+
information. `mergesort` is the only stable algorithm. For
4077+
DataFrames, this option is only applied when sorting on a single
4078+
column or label.
40754079
na_position : {'first', 'last'}, default 'last'
4076-
`first` puts NaNs at the beginning, `last` puts NaNs at the end.
4077-
Not implemented for MultiIndex.
4080+
Puts NaNs at the beginning if `first`; `last` puts NaNs at the end.
4081+
Not implemented for MultiIndex.
40784082
sort_remaining : bool, default True
4079-
if true and sorting by level and index is multilevel, sort by other
4080-
levels too (in order) after sorting by specified level
4083+
If True and sorting by level and index is multilevel, sort by other
4084+
levels too (in order) after sorting by specified level.
40814085
40824086
Returns
40834087
-------
4084-
sorted_obj : %(klass)s
4088+
sorted_obj : DataFrame or None
4089+
DataFrame with sorted index if inplace=False, None otherwise.
40854090
"""
40864091
inplace = validate_bool_kwarg(inplace, 'inplace')
40874092
axis = self._get_axis_number(axis)

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2857,13 +2857,13 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
28572857
If 'first' puts NaNs at the beginning, 'last' puts NaNs at the end.
28582858
Not implemented for MultiIndex.
28592859
sort_remaining : bool, default True
2860-
If true and sorting by level and index is multilevel, sort by other
2860+
If True and sorting by level and index is multilevel, sort by other
28612861
levels too (in order) after sorting by specified level.
28622862
28632863
Returns
28642864
-------
28652865
pandas.Series
2866-
The original Series sorted by the labels
2866+
The original Series sorted by the labels.
28672867
28682868
See Also
28692869
--------

0 commit comments

Comments
 (0)