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

Closed
buyology opened this Issue Mar 17, 2017 · 2 comments

Comments

Projects
None yet
3 participants
Contributor

buyology commented Mar 17, 2017

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

Contributor

TomAugspurger commented Mar 17, 2017 edited

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 added this to the 0.20.0 milestone Mar 17, 2017

@jreback jreback modified the milestone: Next Major Release, 0.20.0 Mar 17, 2017

@buyology buyology added a commit to buyology/pandas that referenced this issue Mar 20, 2017

@buyology buyology Return mode even if single value (#15714) 44dbbb2

buyology referenced this issue Mar 20, 2017

Closed

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

3 of 3 tasks complete

@jreback jreback modified the milestone: 0.20.0, Next Major Release Mar 20, 2017

@jreback jreback modified the milestone: 0.20.0, Next Major Release Mar 23, 2017

@buyology buyology added a commit to buyology/pandas that referenced this issue Mar 24, 2017

@buyology buyology Return mode even if single value (#15714) 26db131

@jreback jreback modified the milestone: 0.20.0, Next Major Release Mar 24, 2017

@jreback jreback added a commit that referenced this issue Mar 29, 2017

@buyology @jreback buyology + jreback BUG: Return mode even if single value (#15714)
Author: Robin <robin.bartholdson@formulate.se>

This patch had conflicts when merged, resolved by
Committer: Jeff Reback <jeff@reback.net>

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)
de589c2

@mattip mattip added a commit to mattip/pandas that referenced this issue Apr 3, 2017

@buyology @mattip buyology + mattip BUG: Return mode even if single value (#15714)
Author: Robin <robin.bartholdson@formulate.se>

This patch had conflicts when merged, resolved by
Committer: Jeff Reback <jeff@reback.net>

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)
548c0a7
Contributor

jreback commented Apr 12, 2017

closed by #15744

jreback closed this Apr 12, 2017

@linebp linebp added a commit to linebp/pandas that referenced this issue Apr 17, 2017

@buyology @linebp buyology + linebp BUG: Return mode even if single value (#15714)
Author: Robin <robin.bartholdson@formulate.se>

This patch had conflicts when merged, resolved by
Committer: Jeff Reback <jeff@reback.net>

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)
53a04cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment