Skip to content

Commit 48ea04f

Browse files
yhaque1213jreback
authored andcommitted
BUG: rolling.count with axis=1 (#26055)
1 parent 187630b commit 48ea04f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ Groupby/Resample/Rolling
389389
- Ensured that ordering of outputs in ``groupby`` aggregation functions is consistent across all versions of Python (:issue:`25692`)
390390
- Ensured that result group order is correct when grouping on an ordered ``Categorical`` and specifying ``observed=True`` (:issue:`25871`, :issue:`25167`)
391391
- Bug in :meth:`pandas.core.window.Rolling.min` and :meth:`pandas.core.window.Rolling.max` that caused a memory leak (:issue:`25893`)
392+
- Bug in :meth:`pandas.core.window.Rolling.count` and `pandas.core.window.Expanding.count` was previously ignoring the axis keyword (:issue:`13503`)
392393
- Bug in :meth:`pandas.core.groupby.GroupBy.idxmax` and :meth:`pandas.core.groupby.GroupBy.idxmin` with datetime column would return incorrect dtype (:issue:`25444`, :issue:`15306`)
393394
- Bug in :meth:`pandas.core.groupby.GroupBy.cumsum`, :meth:`pandas.core.groupby.GroupBy.cumprod`, :meth:`pandas.core.groupby.GroupBy.cummin` and :meth:`pandas.core.groupby.GroupBy.cummax` with categorical column having absent categories, would return incorrect result or segfault (:issue:`16771`)
394395

pandas/core/window.py

+1
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ def count(self):
938938
result = b.notna().astype(int)
939939
result = self._constructor(result, window=window, min_periods=0,
940940
center=self.center,
941+
axis=self.axis,
941942
closed=self.closed).sum()
942943
results.append(result)
943944

pandas/tests/test_window.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def test_iter_raises(self, klass):
648648
with pytest.raises(NotImplementedError):
649649
iter(obj.rolling(2))
650650

651-
def test_rolling_axis(self, axis_frame):
651+
def test_rolling_axis_sum(self, axis_frame):
652652
# see gh-23372.
653653
df = DataFrame(np.ones((10, 20)))
654654
axis = df._get_axis_number(axis_frame)
@@ -667,6 +667,20 @@ def test_rolling_axis(self, axis_frame):
667667
result = df.rolling(3, axis=axis_frame).sum()
668668
tm.assert_frame_equal(result, expected)
669669

670+
def test_rolling_axis_count(self, axis_frame):
671+
# see gh-26055
672+
df = DataFrame({'x': range(3), 'y': range(3)})
673+
674+
axis = df._get_axis_number(axis_frame)
675+
676+
if axis in [0, 'index']:
677+
expected = DataFrame({'x': [1.0, 2.0, 2.0], 'y': [1.0, 2.0, 2.0]})
678+
else:
679+
expected = DataFrame({'x': [1.0, 1.0, 1.0], 'y': [2.0, 2.0, 2.0]})
680+
681+
result = df.rolling(2, axis=axis_frame).count()
682+
tm.assert_frame_equal(result, expected)
683+
670684

671685
class TestExpanding(Base):
672686

0 commit comments

Comments
 (0)