Skip to content

Mode should be defined if the Series consist of only one object #15714

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
buyology opened this issue Mar 17, 2017 · 2 comments
Closed

Mode should be defined if the Series consist of only one object #15714

buyology opened this issue Mar 17, 2017 · 2 comments
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug
Milestone

Comments

@buyology
Copy link

Code Sample

>>> import pandas.core.algorithms as algos
>>> algos.mode([5])
Series([], dtype: int64) 

Problem description

Currently the mode of a series is not defined if the series consist of only one object. This limits the use of the mode as an aggregation method.

Compare this with the behaviour of other libraries, e.g. scipy:

>>> from scipy import stats
>>> scipy.stats.mode([5])
(array([ 5.]), array([ 1.]))

Expected Output

0    5
dtype: int64

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.10.final.0 python-bits: 64 OS: Darwin OS-release: 14.5.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 34.3.1
Cython: None
numpy: 1.8.0rc1
scipy: 0.13.0b1
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: 1.4.8
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.3.1
openpyxl: 2.3.0-b1
xlrd: 1.0.0
xlwt: None
xlsxwriter: 0.9.3
lxml: 3.7.3
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.1.6
pymysql: None
psycopg2: 2.6.2 (dt dec pq3 ext lo64)
jinja2: 2.9.5
boto: 2.42.0
pandas_datareader: None

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Mar 17, 2017

Thanks. Mind sending a PR with a fix?

This limits the use of the mode as an aggregation method.

FYI, pandas' mode isn't necessarily an aggregation, since it doesn't do any tie breaking.

@TomAugspurger TomAugspurger added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug Difficulty Novice labels Mar 17, 2017
@TomAugspurger TomAugspurger added this to the 0.20.0 milestone Mar 17, 2017
@jreback jreback modified the milestones: Next Major Release, 0.20.0 Mar 17, 2017
@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 20, 2017
@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 23, 2017
jreback pushed a commit that referenced this issue Mar 29, 2017
Author: Robin <[email protected]>

This patch had conflicts when merged, resolved by
Committer: Jeff Reback <[email protected]>

Closes #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 (#15714)
44dbbb2 [Robin] Return mode even if single value (#15714)
mattip pushed a commit to mattip/pandas that referenced this issue 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)
@jreback
Copy link
Contributor

jreback commented Apr 12, 2017

closed by #15744

@jreback jreback closed this as completed Apr 12, 2017
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 a pull request may close this issue.

3 participants