Skip to content

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

Closed
@buyology

Description

@buyology

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions