Skip to content

SeriesGroupby.cumsum raises on object dtype #13992

Closed
@agraboso

Description

@agraboso
import pandas as pd

s = pd.Series(list('ABCDEF'))
grouper = pd.Series([0]*3+[1]*3)

The obvious attempt to obtain

0      A
1     AB
2    ABC
3      D
4     DE
5    DEF
dtype: object

using

s.groupby(grouper).cumsum()

raises a DataError: No numeric types to aggregate. A workaround is available via

s.groupby(grouper).apply(pd.Series.cumsum)

SeriesGroupby.cumsum should follow the behavior of SeriesGroupby.sum, where both s.groupby(grouper).apply(pd.Series.sum) and s.groupby(grouper).sum() produce the correct output:

0    ABC
1    DEF
dtype: object

This was introduced some time between 0.15.2 and 0.18.1, as observed here.

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Darwin
OS-release: 15.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 23.0.0
Cython: 0.24
numpy: 1.11.0
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: None
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.0
matplotlib: 1.5.1
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugGroupbyStringsString extension data type and string data

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions