-
-
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
Conversation
@buyology looks like a couple of failing tests. I think we tests this condition of a single object for multiple types, so need to change it in each. |
Tests updated |
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.
just some some minor comments. ping when green.
@@ -5168,9 +5168,8 @@ def _get_agg_axis(self, axis_num): | |||
|
|||
def mode(self, axis=0, numeric_only=False): | |||
""" | |||
Gets the mode(s) of each element along the axis selected. Empty if |
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
to generic.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)
pandas/tests/frame/test_analytics.py
Outdated
dtype=df["B"].dtype), | ||
"C": pd.Series(['e'], dtype=df["C"].dtype)}) | ||
|
||
exp = pd.DataFrame({"A": pd.Series(np.arange(6, dtype='int64'), dtype=df["A"].dtype), |
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.
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.
fixed all but the ones in the hashtable_func_helper.pxi.in
— for some reason it's complaining about lines that I haven't even touched / don't show up in the diffs here on GH
pandas/tests/test_algos.py
Outdated
tm.assert_series_equal(algos.mode(['a', 'b', 'c']), exp) | ||
|
||
def test_mode_single(self): |
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.
this looks duplicated
pandas/tests/test_algos.py
Outdated
@@ -1256,12 +1256,30 @@ def test_no_mode(self): | |||
exp = Series([], dtype=np.float64) | |||
tm.assert_series_equal(algos.mode([]), exp) | |||
|
|||
exp = Series([], dtype=np.int) | |||
def test_mode_single(self): | |||
exp_single = [1] |
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.
add the issue number as a comment
Codecov Report
@@ Coverage Diff @@
## master #15744 +/- ##
==========================================
- Coverage 91.01% 90.98% -0.04%
==========================================
Files 143 143
Lines 49380 49401 +21
==========================================
+ Hits 44943 44946 +3
- Misses 4437 4455 +18
Continue to review full report at Codecov.
|
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 comment
The 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.
data = [1, 1]
(exp should be the same)
can you add a whatsnew note (Bug Fix section). small comment, otherwise lgtm. ping on green. |
can you update |
thanks @buyology nice PR! keep em coming! |
Author: Robin <[email protected]> This patch had conflicts when merged, resolved by Committer: Jeff Reback <[email protected]> Closes pandas-dev#15744 from buyology/issue-15714-fix-mode and squashes the following commits: 8c08cd5 [Robin] Added multi-test and whatsnew note 5f36395 [Robin] Fixed flake issues, removed duplicate test, inserted GH issue number reference 5f829e1 [Robin] Merge conflict 0e2dec0 [Robin] Fixed tests 26db131 [Robin] Return mode even if single value (pandas-dev#15714) 44dbbb2 [Robin] Return mode even if single value (pandas-dev#15714)
test_mode_single
git diff upstream/master | flake8 --diff
(however: it complains about some non-changed rows in hashtable_func_helper.pxi.in)