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

BUG: groupby cumsum with axis=1 computes cumprod #13994

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.19.0.txt
Expand Up @@ -850,6 +850,7 @@ Bug Fixes
~~~~~~~~~

- Bug in ``groupby().shift()``, which could cause a segfault or corruption in rare circumstances when grouping by columns with missing values (:issue:`13813`)
- Bug in ``groupby().cumsum()`` calculating ``cumprod`` when ``axis=1``. (:issue:`13994`)
- Bug in ``pd.read_csv()``, which may cause a segfault or corruption when iterating in large chunks over a stream/file under rare circumstances (:issue:`13703`)
- Bug in ``pd.read_csv()``, which caused BOM files to be incorrectly parsed by not ignoring the BOM (:issue:`4793`)
- Bug in ``io.json.json_normalize()``, where non-ascii keys raised an exception (:issue:`13213`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby.py
Expand Up @@ -1397,7 +1397,7 @@ 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))
return self.apply(lambda x: x.cumsum(axis=axis))

return self._cython_transform('cumsum')

Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_groupby.py
Expand Up @@ -2973,6 +2973,14 @@ def test_cython_api2(self):
result = df.groupby('A', as_index=False).cumsum()
assert_frame_equal(result, expected)

# GH 13994
result = df.groupby('A').cumsum(axis=1)
expected = df.cumsum(axis=1)
assert_frame_equal(result, expected)
result = df.groupby('A').cumprod(axis=1)
expected = df.cumprod(axis=1)
assert_frame_equal(result, expected)

def test_grouping_ndarray(self):
grouped = self.df.groupby(self.df['A'].values)

Expand Down