Skip to content

Commit 85c0177

Browse files
uds5501TomAugspurger
authored andcommitted
BUG: invalid rolling window on empty input (pandas-dev#21291)
(cherry picked from commit 93be27d)
1 parent 222dff8 commit 85c0177

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

doc/source/whatsnew/v0.23.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Groupby/Resample/Rolling
5454
- Bug in :func:`DataFrame.agg` where applying multiple aggregation functions to a :class:`DataFrame` with duplicated column names would cause a stack overflow (:issue:`21063`)
5555
- Bug in :func:`pandas.core.groupby.GroupBy.ffill` and :func:`pandas.core.groupby.GroupBy.bfill` where the fill within a grouping would not always be applied as intended due to the implementations' use of a non-stable sort (:issue:`21207`)
5656
- Bug in :func:`pandas.core.groupby.GroupBy.rank` where results did not scale to 100% when specifying ``method='dense'`` and ``pct=True``
57+
- Bug in :func:`pandas.DataFrame.rolling` and :func:`pandas.Series.rolling` which incorrectly accepted a 0 window size rather than raising (:issue:`21286`)
5758

5859
Strings
5960
^^^^^^^

pandas/core/window.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ def validate(self):
602602
if isinstance(window, (list, tuple, np.ndarray)):
603603
pass
604604
elif is_integer(window):
605-
if window < 0:
606-
raise ValueError("window must be non-negative")
605+
if window <= 0:
606+
raise ValueError("window must be > 0 ")
607607
try:
608608
import scipy.signal as sig
609609
except ImportError:

pandas/tests/test_window.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ def test_constructor(self, which):
389389
c(window=2, min_periods=1, center=False)
390390

391391
# GH 13383
392-
c(0)
393392
with pytest.raises(ValueError):
393+
c(0)
394394
c(-1)
395395

396396
# not valid
@@ -409,7 +409,6 @@ def test_constructor_with_win_type(self, which):
409409
# GH 13383
410410
o = getattr(self, which)
411411
c = o.rolling
412-
c(0, win_type='boxcar')
413412
with pytest.raises(ValueError):
414413
c(-1, win_type='boxcar')
415414

0 commit comments

Comments
 (0)