Skip to content

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
wants to merge 6 commits into from
Closed

Return mode even if single value (#15714) #15744

wants to merge 6 commits into from

Conversation

buyology
Copy link

@jreback jreback added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug labels Mar 20, 2017
@jreback
Copy link
Contributor

jreback commented Mar 20, 2017

@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.

@buyology
Copy link
Author

Tests updated

Copy link
Contributor

@jreback jreback left a 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
Copy link
Contributor

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 :>

Copy link
Author

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?

Copy link
Contributor

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)

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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have flake issues

git diff master | flake8 --diff

see here

Copy link
Author

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

tm.assert_series_equal(algos.mode(['a', 'b', 'c']), exp)

def test_mode_single(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks duplicated

@@ -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]
Copy link
Contributor

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

@jreback jreback added this to the 0.20.0 milestone Mar 24, 2017
@codecov
Copy link

codecov bot commented Mar 27, 2017

Codecov Report

Merging #15744 into master will decrease coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
pandas/core/frame.py 97.56% <ø> (-0.41%) ⬇️
pandas/core/series.py 94.86% <ø> (ø) ⬆️
pandas/core/categorical.py 95.85% <100%> (-1.05%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/tseries/common.py 88.09% <0%> (-1.07%) ⬇️
pandas/types/cast.py 85.31% <0%> (-0.14%) ⬇️
pandas/io/stata.py 93.47% <0%> (-0.05%) ⬇️
pandas/core/algorithms.py 94.43% <0%> (-0.05%) ⬇️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1e29db...8c08cd5. Read the comment docs.

s = Series(data_single, dtype=dt)
exp = Series(exp_single, dtype=dt)
tm.assert_series_equal(algos.mode(s), exp)

Copy link
Contributor

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)

@jreback
Copy link
Contributor

jreback commented Mar 27, 2017

can you add a whatsnew note (Bug Fix section). small comment, otherwise lgtm. ping on green.

@jreback
Copy link
Contributor

jreback commented Mar 29, 2017

can you update

@jreback jreback closed this in de589c2 Mar 29, 2017
@jreback
Copy link
Contributor

jreback commented Mar 29, 2017

thanks @buyology

nice PR!

keep em coming!

mattip pushed a commit to mattip/pandas that referenced this pull request Apr 3, 2017
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mode should be defined if the Series consist of only one object
2 participants