From 2ebe8aeff42f352986b6547adcc146b80eba1c74 Mon Sep 17 00:00:00 2001 From: Bharat Raghunathan Date: Mon, 18 Feb 2019 14:05:26 +0530 Subject: [PATCH 01/10] DOC: Fix #24268 by updating description for keep Fix #24268 by updating `keep` in Series.nlargest --- 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 a5dfe8d43c336..bc11472695d92 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3100,8 +3100,8 @@ def nlargest(self, n=5, keep='first'): When there are duplicate values that cannot all fit in a Series of `n` elements: - - ``first`` : take the first occurrences based on the index order - - ``last`` : take the last occurrences based on the index order + - ``first`` : return the first n occurrences in the given index order + - ``last`` : return the last n occurrences in the reverse of the given index order - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. From ab33dc103d988e7a419b9cff697d5f6e21f7c807 Mon Sep 17 00:00:00 2001 From: Bharat Raghunathan Date: Mon, 18 Feb 2019 14:18:55 +0530 Subject: [PATCH 02/10] Fix PEP8 issues and a typo Fix PEP8 issues in Series.nlargest and a typo in Series.nsmallest --- pandas/core/series.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index bc11472695d92..d482d296d128b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3100,8 +3100,10 @@ def nlargest(self, n=5, keep='first'): When there are duplicate values that cannot all fit in a Series of `n` elements: - - ``first`` : return the first n occurrences in the given index order - - ``last`` : return the last n occurrences in the reverse of the given index order + - ``first`` : return the first `n` occurrences in the + given index order. + - ``last`` : return the last `n` occurrences in the + reverse of the given index order. - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. @@ -3196,8 +3198,10 @@ def nsmallest(self, n=5, keep='first'): When there are duplicate values that cannot all fit in a Series of `n` elements: - - ``first`` : take the first occurrences based on the index order - - ``last`` : take the last occurrences based on the index order + - ``first`` : return the first `n` occurrences in the + given index order. + - ``last`` : return the last `n` occurrences in the + reverse of the given index order. - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. @@ -3238,7 +3242,7 @@ def nsmallest(self, n=5, keep='first'): Monserat 5200 dtype: int64 - The `n` largest elements where ``n=5`` by default. + The `n` smallest elements where ``n=5`` by default. >>> s.nsmallest() Monserat 5200 From 794f3704e62c4e63b2c8f43cfaa148f69697bad9 Mon Sep 17 00:00:00 2001 From: Bharat Raghunathan Date: Mon, 18 Feb 2019 14:20:36 +0530 Subject: [PATCH 03/10] Fix PEP8 issues --- pandas/core/series.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index d482d296d128b..52be1dcddad6e 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3100,9 +3100,9 @@ def nlargest(self, n=5, keep='first'): When there are duplicate values that cannot all fit in a Series of `n` elements: - - ``first`` : return the first `n` occurrences in the + - ``first`` : return the first `n` occurrences in the given index order. - - ``last`` : return the last `n` occurrences in the + - ``last`` : return the last `n` occurrences in the reverse of the given index order. - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. @@ -3198,9 +3198,9 @@ def nsmallest(self, n=5, keep='first'): When there are duplicate values that cannot all fit in a Series of `n` elements: - - ``first`` : return the first `n` occurrences in the + - ``first`` : return the first `n` occurrences in the given index order. - - ``last`` : return the last `n` occurrences in the + - ``last`` : return the last `n` occurrences in the reverse of the given index order. - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. From 28aa45b938934c25e5fbedec01439d86ab9225ea Mon Sep 17 00:00:00 2001 From: Bharat Raghunathan Date: Tue, 19 Feb 2019 09:57:47 +0530 Subject: [PATCH 04/10] Update the description of keep Update according to suggestion by @TomAugsperger --- pandas/core/series.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index 52be1dcddad6e..703c5c9fd8445 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3107,6 +3107,9 @@ def nlargest(self, n=5, keep='first'): - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. + The `keep` parameter determines which ones to keep when there are duplicates. + Regardless of `keep`, the result will be sorted by the row label. + Returns ------- Series @@ -3204,6 +3207,9 @@ def nsmallest(self, n=5, keep='first'): reverse of the given index order. - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. + + The `keep` parameter determines which ones to keep when there are duplicates. + Regardless of `keep`, the result will be sorted by the row label. Returns ------- From c9de2f61b15ac2e5da694d3dbb6b12c34f85a9b6 Mon Sep 17 00:00:00 2001 From: Bharat Raghunathan Date: Tue, 19 Feb 2019 10:04:06 +0530 Subject: [PATCH 05/10] Fix PEP8 issues again --- pandas/core/series.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 703c5c9fd8445..b21cf2ebc8738 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3107,8 +3107,10 @@ def nlargest(self, n=5, keep='first'): - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. - The `keep` parameter determines which ones to keep when there are duplicates. - Regardless of `keep`, the result will be sorted by the row label. + The `keep` parameter determines which ones to keep + when there are duplicates. + Regardless of `keep`, the result will be sorted + by the row label. Returns ------- @@ -3207,9 +3209,11 @@ def nsmallest(self, n=5, keep='first'): reverse of the given index order. - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. - - The `keep` parameter determines which ones to keep when there are duplicates. - Regardless of `keep`, the result will be sorted by the row label. + + The `keep` parameter determines which ones to keep + when there are duplicates. + Regardless of `keep`, the result will be sorted + by the row label. Returns ------- From 62ccfedd21e260fe370b2aa23e0b765b248067b7 Mon Sep 17 00:00:00 2001 From: Bharat Raghunathan Date: Tue, 19 Feb 2019 10:06:29 +0530 Subject: [PATCH 06/10] Fix trailing whitespaces --- pandas/core/series.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index b21cf2ebc8738..635e801944be8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3107,9 +3107,9 @@ def nlargest(self, n=5, keep='first'): - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. - The `keep` parameter determines which ones to keep + The `keep` parameter determines which ones to keep when there are duplicates. - Regardless of `keep`, the result will be sorted + Regardless of `keep`, the result will be sorted by the row label. Returns @@ -3210,9 +3210,9 @@ def nsmallest(self, n=5, keep='first'): - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. - The `keep` parameter determines which ones to keep + The `keep` parameter determines which ones to keep when there are duplicates. - Regardless of `keep`, the result will be sorted + Regardless of `keep`, the result will be sorted by the row label. Returns From 8506a6e7842fd63a72704c47c519476184bd6078 Mon Sep 17 00:00:00 2001 From: Bharat Raghunathan Date: Tue, 19 Feb 2019 13:38:08 +0530 Subject: [PATCH 07/10] Fix some docstring issues (as produced by tests) --- pandas/core/series.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 635e801944be8..cc44cad16f507 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3107,10 +3107,10 @@ def nlargest(self, n=5, keep='first'): - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. - The `keep` parameter determines which ones to keep - when there are duplicates. - Regardless of `keep`, the result will be sorted - by the row label. + The `keep` parameter determines which ones to keep + when there are duplicates. + Regardless of `keep`, the result will be sorted + by the row label. Returns ------- @@ -3210,10 +3210,10 @@ def nsmallest(self, n=5, keep='first'): - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. - The `keep` parameter determines which ones to keep - when there are duplicates. - Regardless of `keep`, the result will be sorted - by the row label. + The `keep` parameter determines which ones to keep + when there are duplicates. + Regardless of `keep`, the result will be sorted + by the row label. Returns ------- From fdb6ba78c4c853dd225a16b20811cd7820be8658 Mon Sep 17 00:00:00 2001 From: Bharat123Rox Date: Wed, 27 Feb 2019 14:43:57 +0530 Subject: [PATCH 08/10] Take suggestions from @TomAugspurger and @WillAyd to improve readability --- pandas/core/series.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index cc44cad16f507..90feebb995ac3 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3101,14 +3101,15 @@ def nlargest(self, n=5, keep='first'): Series of `n` elements: - ``first`` : return the first `n` occurrences in the - given index order. - - ``last`` : return the last `n` occurrences in the - reverse of the given index order. + index order. + - ``last`` : return the last `n` occurrences in the reverse + index order. - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. The `keep` parameter determines which ones to keep - when there are duplicates. + when there are duplicates and returns them in the + order of appearance. Regardless of `keep`, the result will be sorted by the row label. @@ -3204,14 +3205,15 @@ def nsmallest(self, n=5, keep='first'): Series of `n` elements: - ``first`` : return the first `n` occurrences in the - given index order. - - ``last`` : return the last `n` occurrences in the - reverse of the given index order. + index order. + - ``last`` : return the last `n` occurrences in the reverse + index order. - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. The `keep` parameter determines which ones to keep - when there are duplicates. + when there are duplicates and returns them in the + order of appearance. Regardless of `keep`, the result will be sorted by the row label. From 310682af425a55fc93208d2d8bd5a06b2aa6060a Mon Sep 17 00:00:00 2001 From: Bharat123Rox Date: Fri, 1 Mar 2019 23:10:14 +0530 Subject: [PATCH 09/10] Rewording docs according to @WillAyd 's suggestion --- pandas/core/series.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 90feebb995ac3..e5e77aa45f7b0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3100,16 +3100,13 @@ def nlargest(self, n=5, keep='first'): When there are duplicate values that cannot all fit in a Series of `n` elements: - - ``first`` : return the first `n` occurrences in the - index order. - - ``last`` : return the last `n` occurrences in the reverse - index order. + - ``first`` : return the first `n` occurrences in order + of appearance. + - ``last`` : return the last `n` occurrences in reverse + order of appearance. - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. - The `keep` parameter determines which ones to keep - when there are duplicates and returns them in the - order of appearance. Regardless of `keep`, the result will be sorted by the row label. @@ -3204,16 +3201,13 @@ def nsmallest(self, n=5, keep='first'): When there are duplicate values that cannot all fit in a Series of `n` elements: - - ``first`` : return the first `n` occurrences in the - index order. - - ``last`` : return the last `n` occurrences in the reverse - index order. + - ``first`` : return the first `n` occurrences in order + of appearance. + - ``last`` : return the last `n` occurrences in reverse + order of appearance. - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. - The `keep` parameter determines which ones to keep - when there are duplicates and returns them in the - order of appearance. Regardless of `keep`, the result will be sorted by the row label. From 9a8367d638aba233e1f360fe00eedffe492a18d1 Mon Sep 17 00:00:00 2001 From: Bharat123Rox Date: Sun, 3 Mar 2019 10:58:32 +0530 Subject: [PATCH 10/10] Removed the confusing lines as suggested by @jreback --- pandas/core/series.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index a89c8e5c03714..f6598ed1ee614 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3105,9 +3105,6 @@ def nlargest(self, n=5, keep='first'): - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. - Regardless of `keep`, the result will be sorted - by the row label. - Returns ------- Series @@ -3206,9 +3203,6 @@ def nsmallest(self, n=5, keep='first'): - ``all`` : keep all occurrences. This can result in a Series of size larger than `n`. - Regardless of `keep`, the result will be sorted - by the row label. - Returns ------- Series