Skip to content

Commit 722710d

Browse files
committed
TST: add test
1 parent bdf969c commit 722710d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

pandas/tests/window/common.py

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pandas import DataFrame, Series, bdate_range, notna
77
import pandas._testing as tm
8+
from pandas.api.indexers import BaseIndexer
89

910
N, K = 100, 10
1011

@@ -384,3 +385,18 @@ def check_binary_ew_min_periods(name, min_periods, A, B):
384385
Series([1.0]), Series([1.0]), 50, name=name, min_periods=min_periods
385386
)
386387
tm.assert_series_equal(result, Series([np.NaN]))
388+
389+
390+
class ForwardIndexer(BaseIndexer):
391+
# GH 32865
392+
def get_window_bounds(self, num_values, min_periods, center, closed):
393+
start = np.empty(num_values, dtype=np.int64)
394+
end = np.empty(num_values, dtype=np.int64)
395+
for i in range(num_values):
396+
if i + min_periods <= num_values:
397+
start[i] = i
398+
end[i] = min(i + self.window_size, num_values)
399+
else:
400+
start[i] = i
401+
end[i] = i + 1
402+
return start, end

pandas/tests/window/test_rolling.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pandas import DataFrame, Index, Series
1111
import pandas._testing as tm
1212
from pandas.core.window import Rolling
13-
from pandas.tests.window.common import Base
13+
from pandas.tests.window.common import Base, ForwardIndexer
1414

1515

1616
class TestRolling(Base):
@@ -465,3 +465,16 @@ def test_rolling_count_default_min_periods_with_null_values(constructor):
465465
result = constructor(values).rolling(3).count()
466466
expected = constructor(expected_counts)
467467
tm.assert_equal(result, expected)
468+
469+
470+
@pytest.mark.parametrize("constructor", [Series, DataFrame])
471+
def test_rolling_forward_window_min(constructor):
472+
# GH 32865
473+
values = np.arange(10)
474+
expected_min = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, np.nan]
475+
476+
indexer = ForwardIndexer(window_size=3)
477+
rolling = constructor(values).rolling(window=indexer, min_periods=2)
478+
result = rolling.min()
479+
expected = constructor(rolling.apply(lambda x: min(x)))
480+
tm.assert_equal(result, expected)

0 commit comments

Comments
 (0)