-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Return mode even if single value (#15714) #15744
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
44dbbb2
Return mode even if single value (#15714)
26db131
Return mode even if single value (#15714)
0e2dec0
Fixed tests
5f829e1
Merge conflict
5f36395
Fixed flake issues, removed duplicate test, inserted GH issue number …
8c08cd5
Added multi-test and whatsnew note
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
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 |
---|---|---|
|
@@ -1256,10 +1256,20 @@ def test_no_mode(self): | |
exp = Series([], dtype=np.float64) | ||
tm.assert_series_equal(algos.mode([]), exp) | ||
|
||
exp = Series([], dtype=np.int) | ||
# GH 15714 | ||
def test_mode_single(self): | ||
exp_single = [1] | ||
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. add the issue number as a comment |
||
data_single = [1] | ||
|
||
for dt in np.typecodes['AllInteger'] + np.typecodes['Float']: | ||
s = Series(data_single, dtype=dt) | ||
exp = Series(exp_single, dtype=dt) | ||
tm.assert_series_equal(algos.mode(s), exp) | ||
|
||
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. can you add the result for a double-but-same value e.g.
|
||
exp = Series([1], dtype=np.int) | ||
tm.assert_series_equal(algos.mode([1]), exp) | ||
|
||
exp = Series([], dtype=np.object) | ||
exp = Series(['a', 'b', 'c'], dtype=np.object) | ||
tm.assert_series_equal(algos.mode(['a', 'b', 'c']), exp) | ||
|
||
def test_number_mode(self): | ||
|
@@ -1295,7 +1305,8 @@ def test_strobj_mode(self): | |
tm.assert_series_equal(algos.mode(s), exp) | ||
|
||
def test_datelike_mode(self): | ||
exp = Series([], dtype="M8[ns]") | ||
exp = Series(['1900-05-03', '2011-01-03', | ||
'2013-01-02'], dtype="M8[ns]") | ||
s = Series(['2011-01-03', '2013-01-02', | ||
'1900-05-03'], dtype='M8[ns]') | ||
tm.assert_series_equal(algos.mode(s), exp) | ||
|
@@ -1306,7 +1317,8 @@ def test_datelike_mode(self): | |
tm.assert_series_equal(algos.mode(s), exp) | ||
|
||
def test_timedelta_mode(self): | ||
exp = Series([], dtype='timedelta64[ns]') | ||
exp = Series(['-1 days', '0 days', '1 days'], | ||
dtype='timedelta64[ns]') | ||
s = Series(['1 days', '-1 days', '0 days'], | ||
dtype='timedelta64[ns]') | ||
tm.assert_series_equal(algos.mode(s), exp) | ||
|
@@ -1326,13 +1338,13 @@ def test_uint64_overflow(self): | |
s = Series([1, 2**63, 2**63], dtype=np.uint64) | ||
tm.assert_series_equal(algos.mode(s), exp) | ||
|
||
exp = Series([], dtype=np.uint64) | ||
exp = Series([1, 2**63], dtype=np.uint64) | ||
s = Series([1, 2**63], dtype=np.uint64) | ||
tm.assert_series_equal(algos.mode(s), exp) | ||
|
||
def test_categorical(self): | ||
c = Categorical([1, 2]) | ||
exp = Series([], dtype=np.int64) | ||
exp = Series([1, 2], dtype=np.int64) | ||
tm.assert_series_equal(algos.mode(c), exp) | ||
|
||
c = Categorical([1, 'a', 'a']) | ||
|
@@ -1345,7 +1357,7 @@ def test_categorical(self): | |
|
||
def test_index(self): | ||
idx = Index([1, 2, 3]) | ||
exp = Series([], dtype=np.int64) | ||
exp = Series([1, 2, 3], dtype=np.int64) | ||
tm.assert_series_equal(algos.mode(idx), exp) | ||
|
||
idx = Index([1, 'a', 'a']) | ||
|
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.
in this (or followup), we should make this a shared doc-string :>
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.
@jreback — not sure how to do this, I reckon this is to reference the same-ish doc string in all relevant places?
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.
yes you woould move
def mode
togeneric.py
(leaving a stub here and in series for an@Appender
doc-string (look at virtually any other doc-string, e.g.fillna
)can do this as a follow up though (or here, up 2 u)