From 04c8faadee25d631ffd75302ac022d73ff2d66a3 Mon Sep 17 00:00:00 2001 From: Rafael Date: Sat, 10 Mar 2018 15:56:29 -0300 Subject: [PATCH 01/10] sort_values docstring --- pandas/core/series.py | 104 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 069f0372ab6e1..f08554a0cba0f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -76,7 +76,7 @@ __all__ = ['Series'] _shared_doc_kwargs = dict( - axes='index', klass='Series', axes_single_arg="{0, 'index'}", + axes='index', klass='Series', axes_single_arg="{0 or 'index'}", inplace="""inplace : boolean, default False If True, performs operation inplace and returns None.""", unique='np.ndarray', duplicated='Series', @@ -1885,10 +1885,110 @@ def update(self, other): # ---------------------------------------------------------------------- # Reindexing, sorting - @Appender(generic._shared_docs['sort_values'] % _shared_doc_kwargs) + #@Appender(generic._shared_docs['sort_values'] % _shared_doc_kwargs) def sort_values(self, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last'): + """ + Sort by the Series values. + + Sort (or order) a Series into ascending or descending order by some criterion. + + Parameters + ---------- + axis : {0 or ‘index’}, default 0 + Axis to direct sorting. + ascending : bool, default True + Sort ascending (True) or descending (False). + inplace : bool, default False + If True, perform operation in-place. + kind : {‘quicksort’, ‘mergesort’ or ‘heapsort’}, default ‘quicksort’ + Choice of sorting algorithm. See also ndarray.np.sort [1]_ for more information. `mergesort` is the only stable + algorithm. + na_position : {'first' or 'last'}, default 'last' + Argument `first` puts NaNs at the beginning, `last` puts NaNs at the end. + Returns + ------- + sorted_obj : Series + Series ordered by values. + + See Also + -------- + Series.sort_index : Sort by the Series indices. + DataFrame.sort_index : Sort DataFrame by indices. + DataFrame.sort_values : Sort by the values along either axis. + + References + ---------- + .. [1] https://docs.scipy.org/doc/numpy/reference/generated/numpy.sort.html + + Examples + -------- + >>> s = pd.Series([np.nan, 1, 232, 323, 1, 2, 3, 45]) + >>> s + 0 NaN + 1 1.0 + 2 232.0 + 3 323.0 + 4 1.0 + 5 2.0 + 6 3.0 + 7 45.0 + dtype: float64 + + **Sort values ascending order** + + >>> s.sort_values(ascending= True) + 1 1.0 + 4 1.0 + 5 2.0 + 6 3.0 + 7 45.0 + 2 232.0 + 3 323.0 + 0 NaN + dtype: float64 + + **Sort values descending order** + + >>> s.sort_values(ascending= False) + 3 323.0 + 2 232.0 + 7 45.0 + 6 3.0 + 5 2.0 + 4 1.0 + 1 1.0 + 0 NaN + dtype: float64 + + **Sort values inplace** + + >>> s.sort_values(ascending= False, inplace= True) + >>> s + 3 323.0 + 2 232.0 + 7 45.0 + 6 3.0 + 5 2.0 + 4 1.0 + 1 1.0 + 0 NaN + dtype: float64 + + **Sort values putting NAs first** + + >>> s.sort_values(na_position= 'first') + 0 NaN + 4 1.0 + 1 1.0 + 5 2.0 + 6 3.0 + 7 45.0 + 2 232.0 + 3 323.0 + dtype: float64 + """ inplace = validate_bool_kwarg(inplace, 'inplace') axis = self._get_axis_number(axis) From 206b7e6b48cc1f4291a0ab119981601afdd85e7c Mon Sep 17 00:00:00 2001 From: Rafael Date: Sat, 10 Mar 2018 16:31:00 -0300 Subject: [PATCH 02/10] fix --- pandas/core/series.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index f08554a0cba0f..6c4a81b542145 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1885,7 +1885,6 @@ def update(self, other): # ---------------------------------------------------------------------- # Reindexing, sorting - #@Appender(generic._shared_docs['sort_values'] % _shared_doc_kwargs) def sort_values(self, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last'): """ @@ -1938,7 +1937,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False, **Sort values ascending order** - >>> s.sort_values(ascending= True) + >>> s.sort_values(ascending=True) 1 1.0 4 1.0 5 2.0 @@ -1951,7 +1950,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False, **Sort values descending order** - >>> s.sort_values(ascending= False) + >>> s.sort_values(ascending=False) 3 323.0 2 232.0 7 45.0 @@ -1964,7 +1963,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False, **Sort values inplace** - >>> s.sort_values(ascending= False, inplace= True) + >>> s.sort_values(ascending=False, inplace=True) >>> s 3 323.0 2 232.0 @@ -1978,7 +1977,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False, **Sort values putting NAs first** - >>> s.sort_values(na_position= 'first') + >>> s.sort_values(na_position='first') 0 NaN 4 1.0 1 1.0 From 388ed2b81b04ec55e0dc4e27250b50e55103b0f1 Mon Sep 17 00:00:00 2001 From: Rafael Date: Sat, 10 Mar 2018 16:41:04 -0300 Subject: [PATCH 03/10] fix --- pandas/core/series.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 6c4a81b542145..484de6c9bb692 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1897,7 +1897,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False, axis : {0 or ‘index’}, default 0 Axis to direct sorting. ascending : bool, default True - Sort ascending (True) or descending (False). + Sort ascending (`True`) or descending (`False`). inplace : bool, default False If True, perform operation in-place. kind : {‘quicksort’, ‘mergesort’ or ‘heapsort’}, default ‘quicksort’ @@ -1908,7 +1908,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False, Returns ------- - sorted_obj : Series + Series Series ordered by values. See Also @@ -1935,7 +1935,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False, 7 45.0 dtype: float64 - **Sort values ascending order** + Sort values ascending order >>> s.sort_values(ascending=True) 1 1.0 @@ -1948,7 +1948,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False, 0 NaN dtype: float64 - **Sort values descending order** + Sort values descending order >>> s.sort_values(ascending=False) 3 323.0 @@ -1961,7 +1961,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False, 0 NaN dtype: float64 - **Sort values inplace** + Sort values inplace >>> s.sort_values(ascending=False, inplace=True) >>> s @@ -1975,7 +1975,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False, 0 NaN dtype: float64 - **Sort values putting NAs first** + Sort values putting NAs first >>> s.sort_values(na_position='first') 0 NaN From 027e1e5e797aee6c0332ea6f61ecb1d0d02c6edd Mon Sep 17 00:00:00 2001 From: Rafael Date: Sat, 10 Mar 2018 18:24:05 -0300 Subject: [PATCH 04/10] fix type True/False --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 484de6c9bb692..a8b0bf1cd07a1 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1897,7 +1897,7 @@ def sort_values(self, axis=0, ascending=True, inplace=False, axis : {0 or ‘index’}, default 0 Axis to direct sorting. ascending : bool, default True - Sort ascending (`True`) or descending (`False`). + If `True` sort values into ascending order, otherwise descending. inplace : bool, default False If True, perform operation in-place. kind : {‘quicksort’, ‘mergesort’ or ‘heapsort’}, default ‘quicksort’ From fef8f4cc855bdf0c55fb2468d0a67118485222a4 Mon Sep 17 00:00:00 2001 From: Rafael Date: Sat, 10 Mar 2018 20:16:41 -0300 Subject: [PATCH 05/10] fix reviewed pull request --- pandas/core/series.py | 107 ++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index a8b0bf1cd07a1..de426184cca70 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1890,21 +1890,24 @@ def sort_values(self, axis=0, ascending=True, inplace=False, """ Sort by the Series values. - Sort (or order) a Series into ascending or descending order by some criterion. + Sort (or order) a Series in ascending or descending order by some + criterion. Parameters ---------- axis : {0 or ‘index’}, default 0 - Axis to direct sorting. + Axis to direct sorting. The value `index` is accepted for + compatibility with DataFrame.sort_values. ascending : bool, default True - If `True` sort values into ascending order, otherwise descending. + If `True` sort values in ascending order, otherwise descending. inplace : bool, default False If True, perform operation in-place. kind : {‘quicksort’, ‘mergesort’ or ‘heapsort’}, default ‘quicksort’ - Choice of sorting algorithm. See also ndarray.np.sort [1]_ for more information. `mergesort` is the only stable - algorithm. + Choice of sorting algorithm. See also :func:`np.sort` for more + information. `mergesort` is the only stable algorithm. na_position : {'first' or 'last'}, default 'last' - Argument `first` puts NaNs at the beginning, `last` puts NaNs at the end. + Argument `first` puts NaNs at the beginning, `last` puts NaNs at + the end. Returns ------- @@ -1917,76 +1920,76 @@ def sort_values(self, axis=0, ascending=True, inplace=False, DataFrame.sort_index : Sort DataFrame by indices. DataFrame.sort_values : Sort by the values along either axis. - References - ---------- - .. [1] https://docs.scipy.org/doc/numpy/reference/generated/numpy.sort.html - Examples -------- - >>> s = pd.Series([np.nan, 1, 232, 323, 1, 2, 3, 45]) + >>> s = pd.Series([np.nan, 1, 3, 5, 10]) >>> s - 0 NaN - 1 1.0 - 2 232.0 - 3 323.0 - 4 1.0 - 5 2.0 - 6 3.0 - 7 45.0 + 0 NaN + 1 1.0 + 2 3.0 + 3 5.0 + 4 10.0 dtype: float64 - Sort values ascending order + Sort values ascending order (default behaviour) >>> s.sort_values(ascending=True) - 1 1.0 - 4 1.0 - 5 2.0 - 6 3.0 - 7 45.0 - 2 232.0 - 3 323.0 - 0 NaN + 1 1.0 + 2 3.0 + 3 5.0 + 4 10.0 + 0 NaN dtype: float64 Sort values descending order >>> s.sort_values(ascending=False) - 3 323.0 - 2 232.0 - 7 45.0 - 6 3.0 - 5 2.0 - 4 1.0 - 1 1.0 - 0 NaN + 4 10.0 + 3 5.0 + 2 3.0 + 1 1.0 + 0 NaN dtype: float64 Sort values inplace >>> s.sort_values(ascending=False, inplace=True) >>> s - 3 323.0 - 2 232.0 - 7 45.0 - 6 3.0 - 5 2.0 - 4 1.0 - 1 1.0 - 0 NaN + 4 10.0 + 3 5.0 + 2 3.0 + 1 1.0 + 0 NaN dtype: float64 Sort values putting NAs first >>> s.sort_values(na_position='first') - 0 NaN - 4 1.0 - 1 1.0 - 5 2.0 - 6 3.0 - 7 45.0 - 2 232.0 - 3 323.0 + 0 NaN + 1 1.0 + 2 3.0 + 3 5.0 + 4 10.0 dtype: float64 + + Sort a series of strings + + >>> s = pd.Series(['z', 'b', 'd', 'a', 'c']) + >>> s + 0 z + 1 b + 2 d + 3 a + 4 c + dtype: object + + >>> s.sort_values() + 3 a + 1 b + 4 c + 2 d + 0 z + dtype: object """ inplace = validate_bool_kwarg(inplace, 'inplace') axis = self._get_axis_number(axis) From 3c61e6e80b1e1a6ba3580a4163b54f414557af96 Mon Sep 17 00:00:00 2001 From: Rafael Date: Sat, 10 Mar 2018 20:30:10 -0300 Subject: [PATCH 06/10] change example ordered as suggested --- pandas/core/series.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index de426184cca70..1427dfbe94cb1 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1922,13 +1922,13 @@ def sort_values(self, axis=0, ascending=True, inplace=False, Examples -------- - >>> s = pd.Series([np.nan, 1, 3, 5, 10]) + >>> s = pd.Series([np.nan, 1, 3, 10, 5]) >>> s 0 NaN 1 1.0 2 3.0 - 3 5.0 - 4 10.0 + 3 10.0 + 4 5.0 dtype: float64 Sort values ascending order (default behaviour) @@ -1936,16 +1936,16 @@ def sort_values(self, axis=0, ascending=True, inplace=False, >>> s.sort_values(ascending=True) 1 1.0 2 3.0 - 3 5.0 - 4 10.0 + 4 5.0 + 3 10.0 0 NaN dtype: float64 Sort values descending order >>> s.sort_values(ascending=False) - 4 10.0 - 3 5.0 + 3 10.0 + 4 5.0 2 3.0 1 1.0 0 NaN @@ -1955,8 +1955,8 @@ def sort_values(self, axis=0, ascending=True, inplace=False, >>> s.sort_values(ascending=False, inplace=True) >>> s - 4 10.0 - 3 5.0 + 3 10.0 + 4 5.0 2 3.0 1 1.0 0 NaN @@ -1968,8 +1968,8 @@ def sort_values(self, axis=0, ascending=True, inplace=False, 0 NaN 1 1.0 2 3.0 - 3 5.0 - 4 10.0 + 4 5.0 + 3 10.0 dtype: float64 Sort a series of strings From 3d190512dfbd6c4c0ac75b363643340302392bfe Mon Sep 17 00:00:00 2001 From: Rafael Date: Sun, 11 Mar 2018 10:53:24 -0300 Subject: [PATCH 07/10] Fix short description --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 1427dfbe94cb1..3c81de3ef359d 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1888,9 +1888,9 @@ def update(self, other): def sort_values(self, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last'): """ - Sort by the Series values. + Sort by the values. - Sort (or order) a Series in ascending or descending order by some + Sort a Series in ascending or descending order by some criterion. Parameters From 8b09ee59037d96a6d461b2e8aac1303a5c2eb511 Mon Sep 17 00:00:00 2001 From: Rafael Date: Mon, 12 Mar 2018 08:35:51 -0300 Subject: [PATCH 08/10] fix quotes --- pandas/core/series.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 3c81de3ef359d..e89b3569f41ba 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1895,18 +1895,18 @@ def sort_values(self, axis=0, ascending=True, inplace=False, Parameters ---------- - axis : {0 or ‘index’}, default 0 - Axis to direct sorting. The value `index` is accepted for + axis : {0 or 'index'}, default 0 + Axis to direct sorting. The value 'index' is accepted for compatibility with DataFrame.sort_values. ascending : bool, default True - If `True` sort values in ascending order, otherwise descending. + If True sort values in ascending order, otherwise descending. inplace : bool, default False If True, perform operation in-place. - kind : {‘quicksort’, ‘mergesort’ or ‘heapsort’}, default ‘quicksort’ - Choice of sorting algorithm. See also :func:`np.sort` for more - information. `mergesort` is the only stable algorithm. + kind : {'quicksort', 'mergesort' or 'heapsort'}, default 'quicksort' + Choice of sorting algorithm. See also :func:'numpy.sort' for more + information. 'mergesort' is the only stable algorithm. na_position : {'first' or 'last'}, default 'last' - Argument `first` puts NaNs at the beginning, `last` puts NaNs at + Argument 'first' puts NaNs at the beginning, 'last' puts NaNs at the end. Returns From afc528d4110cb24f249c5d256d249ca2ff36b9d2 Mon Sep 17 00:00:00 2001 From: Rafael Date: Mon, 12 Mar 2018 08:39:12 -0300 Subject: [PATCH 09/10] fix ident --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index e89b3569f41ba..92c9f0a98f6e7 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1906,8 +1906,8 @@ def sort_values(self, axis=0, ascending=True, inplace=False, Choice of sorting algorithm. See also :func:'numpy.sort' for more information. 'mergesort' is the only stable algorithm. na_position : {'first' or 'last'}, default 'last' - Argument 'first' puts NaNs at the beginning, 'last' puts NaNs at - the end. + Argument 'first' puts NaNs at the beginning, 'last' puts NaNs at + the end. Returns ------- From 9717c8b97f9d43754dcabe0f286381b408ec6835 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Mon, 12 Mar 2018 15:59:16 +0100 Subject: [PATCH 10/10] Update series.py --- pandas/core/series.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 92c9f0a98f6e7..1e2ae673d3c4c 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1899,11 +1899,11 @@ def sort_values(self, axis=0, ascending=True, inplace=False, Axis to direct sorting. The value 'index' is accepted for compatibility with DataFrame.sort_values. ascending : bool, default True - If True sort values in ascending order, otherwise descending. + If True, sort values in ascending order, otherwise descending. inplace : bool, default False If True, perform operation in-place. kind : {'quicksort', 'mergesort' or 'heapsort'}, default 'quicksort' - Choice of sorting algorithm. See also :func:'numpy.sort' for more + Choice of sorting algorithm. See also :func:`numpy.sort` for more information. 'mergesort' is the only stable algorithm. na_position : {'first' or 'last'}, default 'last' Argument 'first' puts NaNs at the beginning, 'last' puts NaNs at @@ -1917,8 +1917,8 @@ def sort_values(self, axis=0, ascending=True, inplace=False, See Also -------- Series.sort_index : Sort by the Series indices. + DataFrame.sort_values : Sort DataFrame by the values along either axis. DataFrame.sort_index : Sort DataFrame by indices. - DataFrame.sort_values : Sort by the values along either axis. Examples --------