Skip to content

BUG: rolling.count with axis=1 #26055

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

Merged
merged 31 commits into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
da47224
Added axis to constructor call in count
yhaque1213 Apr 11, 2019
c64c76a
TST: GH26055 added test_count_axis to TestRolling
yhaque1213 Apr 12, 2019
90c6915
TST: fixed asserts and pep8 for test_count_axis()
yhaque1213 Apr 12, 2019
4906502
TST: GH26055 rebasing with master
yhaque1213 Apr 13, 2019
c6e1232
TST: GH26055 added whatsnew entry and renamed result and expected var…
yhaque1213 Apr 18, 2019
41ae7fe
TST: GH26055 corrected doc errors and test pep8 errors
yhaque1213 Apr 18, 2019
12065b6
TST: GH26055 fixed comment typo
yhaque1213 Apr 19, 2019
80c8648
TST: GH26055 fixed docs description and added axis_frame to test
yhaque1213 Apr 19, 2019
0f94d87
Combined description in doc and modified if statement in test to corr…
yhaque1213 Apr 20, 2019
1c0f475
TST: GH26055 Same changes as previous commit, merge did not pass chec…
yhaque1213 Apr 20, 2019
b0eae9e
Merge branch 'master' into count-axis-fix
yhaque1213 Apr 20, 2019
0317be0
CLN: GH26055 fixed doc and undid unintentionally added commits
yhaque1213 Apr 22, 2019
852ed4a
DOC: GH26055 removed extra doc line
yhaque1213 Apr 22, 2019
0777c54
DOC: GH26055 removed extra doc lines
yhaque1213 Apr 22, 2019
6c99ab3
DOC: GH26055 readded accidentally removed doc lines
yhaque1213 Apr 22, 2019
5b87937
DOC: GH26055 removed extra space
yhaque1213 Apr 22, 2019
25d6cb2
DOC: GH26055 merged doc conflicts
yhaque1213 Apr 22, 2019
73208dc
Added axis to constructor call in count
yhaque1213 Apr 11, 2019
308077f
TST: GH26055 merging test conflicts
yhaque1213 Apr 22, 2019
1265757
BUG: GH26055 removed extra assignment in constructor call
yhaque1213 Apr 22, 2019
a23c176
DOC: GH26055 removed rebase message
yhaque1213 Apr 22, 2019
42c10af
DOC: GH26055 merging doc conflicts
yhaque1213 Apr 22, 2019
fff256d
DOC: GH26055 updated docs to reserve merge conflict
yhaque1213 Apr 22, 2019
3ba5d35
DOC: GH26055 removed typo from doc
yhaque1213 Apr 26, 2019
9b2b960
Added axis to constructor call in count
yhaque1213 Apr 11, 2019
b8a6cae
DOC: GH26055 removed extra doc lines
yhaque1213 Apr 22, 2019
34e3018
DOC: GH26055 readded accidentally removed doc lines
yhaque1213 Apr 22, 2019
36d1c4e
DOC: GH26055 removed extra space
yhaque1213 Apr 22, 2019
499d910
BUG: GH26055 removed extra assignment in constructor call
yhaque1213 Apr 22, 2019
2786a8c
DOC: GH26055 removed rebase message
yhaque1213 Apr 22, 2019
d040376
DOC: GH26055 removed typo
yhaque1213 Apr 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ Groupby/Resample/Rolling
- Ensured that ordering of outputs in ``groupby`` aggregation functions is consistent across all versions of Python (:issue:`25692`)
- Ensured that result group order is correct when grouping on an ordered ``Categorical`` and specifying ``observed=True`` (:issue:`25871`, :issue:`25167`)
- Bug in :meth:`pandas.core.window.Rolling.min` and :meth:`pandas.core.window.Rolling.max` that caused a memory leak (:issue:`25893`)
- Bug in :meth:`pandas.core.window.Rolling.count` and `pandas.core.window.Expanding.count` was previously ignoring the axis keyword (:issue:`13503`)
- 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`)
- 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`)

Expand Down
1 change: 1 addition & 0 deletions pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ def count(self):
result = b.notna().astype(int)
result = self._constructor(result, window=window, min_periods=0,
center=self.center,
axis=self.axis,
closed=self.closed).sum()
results.append(result)

Expand Down
16 changes: 15 additions & 1 deletion pandas/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def test_iter_raises(self, klass):
with pytest.raises(NotImplementedError):
iter(obj.rolling(2))

def test_rolling_axis(self, axis_frame):
def test_rolling_axis_sum(self, axis_frame):
# see gh-23372.
df = DataFrame(np.ones((10, 20)))
axis = df._get_axis_number(axis_frame)
Expand All @@ -667,6 +667,20 @@ def test_rolling_axis(self, axis_frame):
result = df.rolling(3, axis=axis_frame).sum()
tm.assert_frame_equal(result, expected)

def test_rolling_axis_count(self, axis_frame):
# see gh-26055
df = DataFrame({'x': range(3), 'y': range(3)})

axis = df._get_axis_number(axis_frame)

if axis in [0, 'index']:
expected = DataFrame({'x': [1.0, 2.0, 2.0], 'y': [1.0, 2.0, 2.0]})
else:
expected = DataFrame({'x': [1.0, 1.0, 1.0], 'y': [2.0, 2.0, 2.0]})

result = df.rolling(2, axis=axis_frame).count()
tm.assert_frame_equal(result, expected)


class TestExpanding(Base):

Expand Down