|
3 | 3 |
|
4 | 4 | from pandas import DataFrame, Series
|
5 | 5 | import pandas._testing as tm
|
6 |
| -from pandas.api.indexers import BaseIndexer |
| 6 | +from pandas.api.indexers import BaseIndexer, FixedForwardWindowIndexer |
7 | 7 | from pandas.core.window.indexers import ExpandingIndexer
|
8 | 8 |
|
9 | 9 |
|
@@ -105,19 +105,21 @@ def get_window_bounds(self, num_values, min_periods, center, closed):
|
105 | 105 | )
|
106 | 106 | def test_rolling_forward_window(constructor, func, alt_func, expected):
|
107 | 107 | # GH 32865
|
108 |
| - class ForwardIndexer(BaseIndexer): |
109 |
| - def get_window_bounds(self, num_values, min_periods, center, closed): |
110 |
| - start = np.arange(num_values, dtype="int64") |
111 |
| - end_s = start[: -self.window_size] + self.window_size |
112 |
| - end_e = np.full(self.window_size, num_values, dtype="int64") |
113 |
| - end = np.concatenate([end_s, end_e]) |
114 |
| - |
115 |
| - return start, end |
116 |
| - |
117 | 108 | values = np.arange(10)
|
118 | 109 | values[5] = 100.0
|
119 | 110 |
|
120 |
| - indexer = ForwardIndexer(window_size=3) |
| 111 | + indexer = FixedForwardWindowIndexer(window_size=3) |
| 112 | + |
| 113 | + match = "Forward-looking windows can't have center=True" |
| 114 | + with pytest.raises(ValueError, match=match): |
| 115 | + rolling = constructor(values).rolling(window=indexer, center=True) |
| 116 | + result = getattr(rolling, func)() |
| 117 | + |
| 118 | + match = "Forward-looking windows don't support setting the closed argument" |
| 119 | + with pytest.raises(ValueError, match=match): |
| 120 | + rolling = constructor(values).rolling(window=indexer, closed="right") |
| 121 | + result = getattr(rolling, func)() |
| 122 | + |
121 | 123 | rolling = constructor(values).rolling(window=indexer, min_periods=2)
|
122 | 124 | result = getattr(rolling, func)()
|
123 | 125 | expected = constructor(expected)
|
|
0 commit comments