-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: Fix #24268 by updating description for keep in Series.nlargest #25358
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2ebe8ae
DOC: Fix #24268 by updating description for keep
bharatr21 ab33dc1
Fix PEP8 issues and a typo
bharatr21 794f370
Fix PEP8 issues
bharatr21 28aa45b
Update the description of keep
bharatr21 c9de2f6
Fix PEP8 issues again
bharatr21 62ccfed
Fix trailing whitespaces
bharatr21 8506a6e
Fix some docstring issues (as produced by tests)
bharatr21 fdb6ba7
Take suggestions from @TomAugspurger and @WillAyd to improve readability
310682a
Rewording docs according to @WillAyd 's suggestion
bharatr21 5c56fad
Merge remote-tracking branch 'upstream/master'
bharatr21 9a8367d
Removed the confusing lines as suggested by @jreback
bharatr21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3100,11 +3100,18 @@ 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`. | ||
|
||
The `keep` parameter determines which ones to keep | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need this sentence as it is stated above |
||
when there are duplicates. | ||
Regardless of `keep`, the result will be sorted | ||
bharatr21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
by the row label. | ||
|
||
Returns | ||
------- | ||
Series | ||
|
@@ -3196,11 +3203,18 @@ 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`. | ||
|
||
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 | ||
|
@@ -3238,7 +3252,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. | ||
bharatr21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
>>> s.nsmallest() | ||
Monserat 5200 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is "given index order" the correct description? I interpreted
#24268 (comment) as a modification on the result. So below the descriptions of first / last / all, I would note something like
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.
I will include this, but when keep="last", the row labels are sorted in reverse order even in the examples in #24268
And I feel "given index order" is correct because it is "given" by the user as input, if it is not an implicit RangeIndex
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.
I understand what you are writing here but I find the readability rather difficult. Any reason we don't use the same terminology in the
unique
docstring?Uniques are returned in order of appearance
^ obviously accounting for reversal with the
last
argumentThere 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.
@WillAyd What do you suggest me to do? If it's changing the
unique
docstring, I want to leave this as-is, because I still want to somehow emphasize the fact that index order is reversed whenkeep="last"
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.
My suggested wording is
Return the first n occurrences in order of appearance
for first and thenReturn the last n occurrences in reverse order of appearance