Skip to content

Commit a0d05db

Browse files
agrabosojreback
authored andcommitted
BUG: groupby cumsum with axis=1 computes cumprod
closes #13993 Author: agraboso <[email protected]> Closes #13994 from agraboso/fix-13993 and squashes the following commits: 56dc1c7 [agraboso] BUG: groupby cumsum with axis=1 computes cumprod
1 parent 0236d75 commit a0d05db

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v0.19.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ Bug Fixes
855855
~~~~~~~~~
856856

857857
- Bug in ``groupby().shift()``, which could cause a segfault or corruption in rare circumstances when grouping by columns with missing values (:issue:`13813`)
858+
- Bug in ``groupby().cumsum()`` calculating ``cumprod`` when ``axis=1``. (:issue:`13994`)
858859
- 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`)
859860
- Bug in ``pd.read_csv()``, which caused BOM files to be incorrectly parsed by not ignoring the BOM (:issue:`4793`)
860861
- Bug in ``io.json.json_normalize()``, where non-ascii keys raised an exception (:issue:`13213`)

pandas/core/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ def cumsum(self, axis=0, *args, **kwargs):
13971397
"""Cumulative sum for each group"""
13981398
nv.validate_groupby_func('cumsum', args, kwargs)
13991399
if axis != 0:
1400-
return self.apply(lambda x: x.cumprod(axis=axis))
1400+
return self.apply(lambda x: x.cumsum(axis=axis))
14011401

14021402
return self._cython_transform('cumsum')
14031403

pandas/tests/test_groupby.py

+8
Original file line numberDiff line numberDiff line change
@@ -2973,6 +2973,14 @@ def test_cython_api2(self):
29732973
result = df.groupby('A', as_index=False).cumsum()
29742974
assert_frame_equal(result, expected)
29752975

2976+
# GH 13994
2977+
result = df.groupby('A').cumsum(axis=1)
2978+
expected = df.cumsum(axis=1)
2979+
assert_frame_equal(result, expected)
2980+
result = df.groupby('A').cumprod(axis=1)
2981+
expected = df.cumprod(axis=1)
2982+
assert_frame_equal(result, expected)
2983+
29762984
def test_grouping_ndarray(self):
29772985
grouped = self.df.groupby(self.df['A'].values)
29782986

0 commit comments

Comments
 (0)