Skip to content

Commit 3a9c089

Browse files
committed
Add checks for expanding/ewm/groupby-rolling and rolling-cov/corr
1 parent 9c225c0 commit 3a9c089

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

pandas/tests/window/test_rolling.py

+44-6
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,64 @@ def test_invalid_constructor(frame_or_series, w):
100100
ExponentialMovingWindowIndexer(window_size=3),
101101
GroupbyIndexer(window_size=3),
102102
VariableOffsetWindowIndexer(
103-
index=date_range("2015-12-26", periods=3), offset=BusinessDay(1)
103+
index=date_range("2015-12-25", periods=5), offset=BusinessDay(1)
104104
),
105105
VariableWindowIndexer(window_size=3),
106106
],
107107
)
108-
def test_constructor_step_not_implemented(window, step):
108+
@pytest.mark.parametrize(
109+
"func",
110+
[
111+
lambda df: df.rolling,
112+
lambda df: df.groupby("key").rolling,
113+
],
114+
)
115+
def test_constructor_step_not_implemented(window, func, step):
109116
# GH 15354
110-
n = 10
111117
df = DataFrame(
112-
{"value": np.arange(n)},
113-
index=date_range("2015-12-24", periods=n, freq="D"),
118+
{"value": np.arange(10), "key": np.array([1] * 5 + [2] * 5)},
119+
index=date_range("2015-12-24", periods=10, freq="D"),
120+
)
121+
f = lambda: func(df)(window=window, step=step)
122+
if step is None:
123+
f()
124+
else:
125+
with pytest.raises(NotImplementedError, match="step not implemented"):
126+
f()
127+
128+
129+
@pytest.mark.parametrize("agg", ["cov", "corr"])
130+
def test_constructor_step_not_implemented_for_cov_corr(agg, step):
131+
# GH 15354
132+
df = DataFrame(
133+
{"value": np.arange(10), "key": np.array([1] * 5 + [2] * 5)},
134+
index=date_range("2015-12-24", periods=10, freq="D"),
114135
)
115-
f = lambda: df.rolling(window=window, step=step)
136+
f = lambda: getattr(df.rolling(window=2, step=step), agg)(df)
116137
if step is None:
117138
f()
118139
else:
119140
with pytest.raises(NotImplementedError, match="step not implemented"):
120141
f()
121142

122143

144+
@pytest.mark.parametrize(
145+
"func",
146+
[
147+
lambda df: df.expanding,
148+
lambda df: df.ewm,
149+
],
150+
)
151+
def test_constructor_step_unsupported(func, step):
152+
# GH 15354
153+
df = DataFrame(
154+
{"value": np.arange(10), "key": np.array([1] * 5 + [2] * 5)},
155+
index=date_range("2015-12-24", periods=10, freq="D"),
156+
)
157+
with pytest.raises(TypeError, match="got an unexpected keyword argument 'step'"):
158+
func(df)(step=step)
159+
160+
123161
@pytest.mark.parametrize("window", [timedelta(days=3), Timedelta(days=3)])
124162
@pytest.mark.parametrize("step", [None])
125163
def test_constructor_with_timedelta_window(window, step):

0 commit comments

Comments
 (0)