Skip to content
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

groupby cumsum with axis=1 computes cumprod #13993

Closed
agraboso opened this issue Aug 13, 2016 · 0 comments
Closed

groupby cumsum with axis=1 computes cumprod #13993

agraboso opened this issue Aug 13, 2016 · 0 comments
Milestone

Comments

@agraboso
Copy link
Contributor

agraboso commented Aug 13, 2016

Code sample

import pandas as pd

df = pd.DataFrame({'A': range(6), 'B': range(6)})
df.groupby('A').cumsum(axis=1)

Output

   A   B
0  0   0
1  1   1
2  2   4
3  3   9
4  4  16
5  5  25

Expected Output

   A   B
0  0   0
1  1   2
2  2   4
3  3   6
4  4   8
5  5  10

The culprit

A single line in pandas.core.groupby:

def cumsum(self, axis=0, *args, **kwargs):
    """Cumulative sum for each group"""
    nv.validate_groupby_func('cumsum', args, kwargs)
    if axis != 0:
        return self.apply(lambda x: x.cumprod(axis=axis))    # <==== should be `cumsum`

    return self._cython_transform('cumsum')

(the result of a copy-paste oversight in this commit)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants