@@ -100,26 +100,64 @@ def test_invalid_constructor(frame_or_series, w):
100
100
ExponentialMovingWindowIndexer (window_size = 3 ),
101
101
GroupbyIndexer (window_size = 3 ),
102
102
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 )
104
104
),
105
105
VariableWindowIndexer (window_size = 3 ),
106
106
],
107
107
)
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 ):
109
116
# GH 15354
110
- n = 10
111
117
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" ),
114
135
)
115
- f = lambda : df .rolling (window = window , step = step )
136
+ f = lambda : getattr ( df .rolling (window = 2 , step = step ), agg )( df )
116
137
if step is None :
117
138
f ()
118
139
else :
119
140
with pytest .raises (NotImplementedError , match = "step not implemented" ):
120
141
f ()
121
142
122
143
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
+
123
161
@pytest .mark .parametrize ("window" , [timedelta (days = 3 ), Timedelta (days = 3 )])
124
162
@pytest .mark .parametrize ("step" , [None ])
125
163
def test_constructor_with_timedelta_window (window , step ):
0 commit comments