-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: series rank has a percentage rank option #5978
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
Merged
+92
−12
Merged
Changes from all commits
Commits
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -3955,6 +3955,48 @@ def test_rank(self): | |
iranks = iseries.rank() | ||
exp = iseries.astype(float).rank() | ||
assert_series_equal(iranks, exp) | ||
iseries = Series(np.arange(5)) + 1.0 | ||
exp = iseries / 5.0 | ||
iranks = iseries.rank(pct=True) | ||
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. I think you have it here, but can you have a test with 'int64' and datetimes (e.g. a date series) (result of course should be float64); 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. done |
||
|
||
assert_series_equal(iranks, exp) | ||
|
||
iseries = Series(np.repeat(1, 100)) | ||
exp = Series(np.repeat(0.505, 100)) | ||
iranks = iseries.rank(pct=True) | ||
assert_series_equal(iranks, exp) | ||
|
||
iseries[1] = np.nan | ||
exp = Series(np.repeat(50.0 / 99.0, 100)) | ||
exp[1] = np.nan | ||
iranks = iseries.rank(pct=True) | ||
assert_series_equal(iranks, exp) | ||
|
||
iseries = Series(np.arange(5)) + 1.0 | ||
iseries[4] = np.nan | ||
exp = iseries / 4.0 | ||
iranks = iseries.rank(pct=True) | ||
assert_series_equal(iranks, exp) | ||
|
||
iseries = Series(np.repeat(np.nan, 100)) | ||
exp = iseries.copy() | ||
iranks = iseries.rank(pct=True) | ||
assert_series_equal(iranks, exp) | ||
|
||
iseries = Series(np.arange(5)) + 1 | ||
iseries[4] = np.nan | ||
exp = iseries / 4.0 | ||
iranks = iseries.rank(pct=True) | ||
assert_series_equal(iranks, exp) | ||
rng = date_range('1/1/1990', periods=5) | ||
|
||
iseries = Series(np.arange(5), rng) + 1 | ||
iseries.ix[4] = np.nan | ||
exp = iseries / 4.0 | ||
iranks = iseries.rank(pct=True) | ||
assert_series_equal(iranks, exp) | ||
|
||
|
||
|
||
def test_from_csv(self): | ||
|
||
|
This file contains hidden or 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
This file contains hidden or 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
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.
can you add a couple of more tests, maybe all nan series and for groupby, group that has 1 element
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 more tests with partial nan's and duplicate values. nan's will always be nan's so not sure if we would ever catch a bug if all nan's.
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.
but that is the check; make sure you propogate nans; the edge cases are always important to test (and usually the hardest to get right)
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.
easy enough. I added that as well.