BUG: Rolling.count modifies 'min_periods' inplace since 1.2.0 #39554
Labels
Bug
Needs Triage
Issue that has not been reviewed by a pandas team member
Window
rolling, ewma, expanding
Milestone
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Output
Problem description
Two sequential calls of
.sum
on the rolling object produces different results if we call.count
between them andmin_periods=None
. The default behavior ofRolling.sum
ifmin_periods
is None is to considermin_periods
to be equal to the window size. Currently,Rolling.count
behaves differently, and considersmin_periods
to be 0 if it is None. #36649 brought a warning that this behavior is deprecated and also refactored.count
implementation. Right after giving a warning, it modifies the original value ofmin_periods
of the rolling object, so the future calls of.sum
and other operations give incorrect results.pandas/pandas/core/window/rolling.py
Lines 2138 to 2149 in 5e02681
Expected Output
Rolling.count
should not modifymin_periods
attribute of the rolling object, or if it is, revert back the original value ofmin_periods
after performingcount
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: