Skip to content

BUG: Weighted rolling aggregations min_periods=0 #51611

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
6 changes: 5 additions & 1 deletion pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,11 @@ def homogeneous_func(values: np.ndarray):
def calc(x):
additional_nans = np.array([np.nan] * offset)
x = np.concatenate((x, additional_nans))
return func(x, window, self.min_periods or len(window))
return func(
x,
window,
self.min_periods if self.min_periods is not None else len(window),
)

with np.errstate(all="ignore"):
# Our weighted aggregations return memoryviews
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/window/test_win_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,16 @@ def test_cmov_window_frame(f, xp, step):
tm.assert_frame_equal(xp, rs)


@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4, 5])
@td.skip_if_no_scipy
def test_cmov_window_na_min_periods(step):
# min_periods
def test_cmov_window_na_min_periods(step, min_periods):
vals = Series(np.random.randn(10))
vals[4] = np.nan
vals[8] = np.nan

xp = vals.rolling(5, min_periods=4, center=True, step=step).mean()
xp = vals.rolling(5, min_periods=min_periods, center=True, step=step).mean()
rs = vals.rolling(
5, win_type="boxcar", min_periods=4, center=True, step=step
5, win_type="boxcar", min_periods=min_periods, center=True, step=step
).mean()
tm.assert_series_equal(xp, rs)

Expand Down