@@ -65,47 +65,40 @@ def test_rolling_mean(self):
65
65
self ._check_moment_func (mom .rolling_mean , np .mean )
66
66
67
67
def test_cmov_mean (self ):
68
+ # GH 8238
68
69
tm ._skip_if_no_scipy ()
69
- try :
70
- from scikits .timeseries .lib import cmov_mean
71
- except ImportError :
72
- raise nose .SkipTest ("no scikits.timeseries" )
73
70
74
- vals = np .random .randn (10 )
75
- xp = cmov_mean (vals , 5 )
71
+ vals = np .array ([6.95 , 15.21 , 4.72 , 9.12 , 13.81 , 13.49 ,
72
+ 16.68 , 9.48 , 10.63 , 14.48 ])
73
+ xp = np .array ([np .nan , np .nan , 9.962 , 11.27 , 11.564 , 12.516 ,
74
+ 12.818 , 12.952 , np .nan , np .nan ])
76
75
77
76
rs = mom .rolling_mean (vals , 5 , center = True )
78
- assert_almost_equal (xp .compressed (), rs [2 :- 2 ])
79
- assert_almost_equal (xp .mask , np .isnan (rs ))
77
+ assert_almost_equal (xp , rs )
80
78
81
79
xp = Series (rs )
82
80
rs = mom .rolling_mean (Series (vals ), 5 , center = True )
83
81
assert_series_equal (xp , rs )
84
82
85
83
def test_cmov_window (self ):
84
+ # GH 8238
86
85
tm ._skip_if_no_scipy ()
87
- try :
88
- from scikits .timeseries .lib import cmov_window
89
- except ImportError :
90
- raise nose .SkipTest ("no scikits.timeseries" )
91
86
92
- vals = np .random .randn (10 )
93
- xp = cmov_window (vals , 5 , 'boxcar' )
87
+ vals = np .array ([6.95 , 15.21 , 4.72 , 9.12 , 13.81 ,
88
+ 13.49 , 16.68 , 9.48 , 10.63 , 14.48 ])
89
+ xp = np .array ([np .nan , np .nan , 9.962 , 11.27 , 11.564 , 12.516 ,
90
+ 12.818 , 12.952 , np .nan , np .nan ])
94
91
95
92
rs = mom .rolling_window (vals , 5 , 'boxcar' , center = True )
96
- assert_almost_equal (xp .compressed (), rs [2 :- 2 ])
97
- assert_almost_equal (xp .mask , np .isnan (rs ))
93
+ assert_almost_equal (xp , rs )
98
94
99
95
xp = Series (rs )
100
96
rs = mom .rolling_window (Series (vals ), 5 , 'boxcar' , center = True )
101
97
assert_series_equal (xp , rs )
102
98
103
99
def test_cmov_window_corner (self ):
100
+ # GH 8238
104
101
tm ._skip_if_no_scipy ()
105
- try :
106
- from scikits .timeseries .lib import cmov_window
107
- except ImportError :
108
- raise nose .SkipTest ("no scikits.timeseries" )
109
102
110
103
# all nan
111
104
vals = np .empty (10 , dtype = float )
@@ -125,24 +118,37 @@ def test_cmov_window_corner(self):
125
118
self .assertEqual (len (rs ), 5 )
126
119
127
120
def test_cmov_window_frame (self ):
121
+ # Gh 8238
128
122
tm ._skip_if_no_scipy ()
129
- try :
130
- from scikits .timeseries .lib import cmov_window
131
- except ImportError :
132
- raise nose .SkipTest ("no scikits.timeseries" )
123
+
124
+ vals = np .array ([[ 12.18 , 3.64 ],
125
+ [ 10.18 , 9.16 ],
126
+ [ 13.24 , 14.61 ],
127
+ [ 4.51 , 8.11 ],
128
+ [ 6.15 , 11.44 ],
129
+ [ 9.14 , 6.21 ],
130
+ [ 11.31 , 10.67 ],
131
+ [ 2.94 , 6.51 ],
132
+ [ 9.42 , 8.39 ],
133
+ [ 12.44 , 7.34 ]])
134
+
135
+ xp = np .array ([[ np .nan , np .nan ],
136
+ [ np .nan , np .nan ],
137
+ [ 9.252 , 9.392 ],
138
+ [ 8.644 , 9.906 ],
139
+ [ 8.87 , 10.208 ],
140
+ [ 6.81 , 8.588 ],
141
+ [ 7.792 , 8.644 ],
142
+ [ 9.05 , 7.824 ],
143
+ [ np .nan , np .nan ],
144
+ [ np .nan , np .nan ]])
133
145
134
146
# DataFrame
135
- vals = np .random .randn (10 , 2 )
136
- xp = cmov_window (vals , 5 , 'boxcar' )
137
147
rs = mom .rolling_window (DataFrame (vals ), 5 , 'boxcar' , center = True )
138
148
assert_frame_equal (DataFrame (xp ), rs )
139
149
140
150
def test_cmov_window_na_min_periods (self ):
141
151
tm ._skip_if_no_scipy ()
142
- try :
143
- from scikits .timeseries .lib import cmov_window
144
- except ImportError :
145
- raise nose .SkipTest ("no scikits.timeseries" )
146
152
147
153
# min_periods
148
154
vals = Series (np .random .randn (10 ))
@@ -155,39 +161,136 @@ def test_cmov_window_na_min_periods(self):
155
161
assert_series_equal (xp , rs )
156
162
157
163
def test_cmov_window_regular (self ):
164
+ # GH 8238
158
165
tm ._skip_if_no_scipy ()
159
- try :
160
- from scikits .timeseries .lib import cmov_window
161
- except ImportError :
162
- raise nose .SkipTest ("no scikits.timeseries" )
163
166
164
167
win_types = ['triang' , 'blackman' , 'hamming' , 'bartlett' , 'bohman' ,
165
168
'blackmanharris' , 'nuttall' , 'barthann' ]
169
+
170
+ vals = np .array ([6.95 , 15.21 , 4.72 , 9.12 , 13.81 ,
171
+ 13.49 , 16.68 , 9.48 , 10.63 , 14.48 ])
172
+ xps = {
173
+ 'hamming' : [np .nan , np .nan , 8.71384 , 9.56348 , 12.38009 ,
174
+ 14.03687 , 13.8567 , 11.81473 , np .nan , np .nan ],
175
+ 'triang' : [np .nan , np .nan , 9.28667 , 10.34667 , 12.00556 ,
176
+ 13.33889 , 13.38 , 12.33667 , np .nan , np .nan ],
177
+ 'barthann' : [np .nan , np .nan , 8.4425 , 9.1925 , 12.5575 ,
178
+ 14.3675 , 14.0825 , 11.5675 , np .nan , np .nan ],
179
+ 'bohman' : [np .nan , np .nan , 7.61599 , 9.1764 , 12.83559 ,
180
+ 14.17267 , 14.65923 , 11.10401 , np .nan , np .nan ],
181
+ 'blackmanharris' : [np .nan , np .nan , 6.97691 , 9.16438 , 13.05052 ,
182
+ 14.02156 , 15.10512 , 10.74574 , np .nan , np .nan ],
183
+ 'nuttall' : [np .nan , np .nan , 7.04618 , 9.16786 , 13.02671 ,
184
+ 14.03559 , 15.05657 , 10.78514 , np .nan , np .nan ],
185
+ 'blackman' : [np .nan , np .nan , 7.73345 , 9.17869 , 12.79607 ,
186
+ 14.20036 , 14.57726 , 11.16988 , np .nan , np .nan ],
187
+ 'bartlett' : [np .nan , np .nan , 8.4425 , 9.1925 , 12.5575 ,
188
+ 14.3675 , 14.0825 , 11.5675 , np .nan , np .nan ]}
189
+
166
190
for wt in win_types :
167
- vals = np .random .randn (10 )
168
- xp = cmov_window (vals , 5 , wt )
191
+ xp = Series (xps [wt ])
192
+ rs = mom .rolling_window (Series (vals ), 5 , wt , center = True )
193
+ assert_series_equal (xp , rs )
194
+
195
+ def test_cmov_window_regular_linear_range (self ):
196
+ # GH 8238
197
+ tm ._skip_if_no_scipy ()
169
198
199
+ win_types = ['triang' , 'blackman' , 'hamming' , 'bartlett' , 'bohman' ,
200
+ 'blackmanharris' , 'nuttall' , 'barthann' ]
201
+
202
+ vals = np .array (range (10 ), dtype = np .float )
203
+ xp = vals .copy ()
204
+ xp [:2 ] = np .nan
205
+ xp [- 2 :] = np .nan
206
+ xp = Series (xp )
207
+
208
+ for wt in win_types :
170
209
rs = mom .rolling_window (Series (vals ), 5 , wt , center = True )
171
- assert_series_equal (Series (xp ), rs )
210
+ assert_series_equal (xp , rs )
211
+
212
+ def test_cmov_window_regular_missing_data (self ):
213
+ # GH 8238
214
+ tm ._skip_if_no_scipy ()
215
+
216
+ win_types = ['triang' , 'blackman' , 'hamming' , 'bartlett' , 'bohman' ,
217
+ 'blackmanharris' , 'nuttall' , 'barthann' ]
218
+
219
+ vals = np .array ([6.95 , 15.21 , 4.72 , 9.12 , 13.81 ,
220
+ 13.49 , 16.68 , np .nan , 10.63 , 14.48 ])
221
+ xps = {
222
+ 'bartlett' : [np .nan , np .nan , 9.70333 , 10.5225 , 8.4425 ,
223
+ 9.1925 , 12.5575 , 14.3675 , 15.61667 , 13.655 ],
224
+ 'blackman' : [np .nan , np .nan , 9.04582 , 11.41536 , 7.73345 ,
225
+ 9.17869 , 12.79607 , 14.20036 , 15.8706 , 13.655 ],
226
+ 'barthann' : [np .nan , np .nan , 9.70333 , 10.5225 , 8.4425 ,
227
+ 9.1925 , 12.5575 , 14.3675 , 15.61667 , 13.655 ],
228
+ 'bohman' : [np .nan , np .nan , 8.9444 , 11.56327 , 7.61599 ,
229
+ 9.1764 , 12.83559 , 14.17267 , 15.90976 , 13.655 ],
230
+ 'hamming' : [np .nan , np .nan , 9.59321 , 10.29694 , 8.71384 ,
231
+ 9.56348 , 12.38009 , 14.20565 , 15.24694 , 13.69758 ],
232
+ 'nuttall' : [np .nan , np .nan , 8.47693 , 12.2821 , 7.04618 ,
233
+ 9.16786 , 13.02671 , 14.03673 , 16.08759 , 13.65553 ],
234
+ 'triang' : [np .nan , np .nan , 9.33167 , 9.76125 , 9.28667 ,
235
+ 10.34667 , 12.00556 , 13.82125 , 14.49429 , 13.765 ],
236
+ 'blackmanharris' : [np .nan , np .nan , 8.42526 , 12.36824 , 6.97691 ,
237
+ 9.16438 , 13.05052 , 14.02175 , 16.1098 ,
238
+ 13.65509 ]
239
+ }
240
+
241
+ for wt in win_types :
242
+ xp = Series (xps [wt ])
243
+ rs = mom .rolling_window (Series (vals ), 5 , wt , min_periods = 3 )
244
+ assert_series_equal (xp , rs )
172
245
173
246
def test_cmov_window_special (self ):
247
+ # GH 8238
174
248
tm ._skip_if_no_scipy ()
175
- try :
176
- from scikits .timeseries .lib import cmov_window
177
- except ImportError :
178
- raise nose .SkipTest ("no scikits.timeseries" )
179
249
180
250
win_types = ['kaiser' , 'gaussian' , 'general_gaussian' , 'slepian' ]
181
251
kwds = [{'beta' : 1. }, {'std' : 1. }, {'power' : 2. , 'width' : 2. },
182
252
{'width' : 0.5 }]
183
253
254
+ vals = np .array ([6.95 , 15.21 , 4.72 , 9.12 , 13.81 ,
255
+ 13.49 , 16.68 , 9.48 , 10.63 , 14.48 ])
256
+
257
+ xps = {
258
+ 'gaussian' : [np .nan , np .nan , 8.97297 , 9.76077 , 12.24763 ,
259
+ 13.89053 , 13.65671 , 12.01002 , np .nan , np .nan ],
260
+ 'general_gaussian' : [np .nan , np .nan , 9.85011 , 10.71589 ,
261
+ 11.73161 , 13.08516 , 12.95111 , 12.74577 ,
262
+ np .nan , np .nan ],
263
+ 'slepian' : [np .nan , np .nan , 9.81073 , 10.89359 , 11.70284 ,
264
+ 12.88331 , 12.96079 , 12.77008 , np .nan , np .nan ],
265
+ 'kaiser' : [np .nan , np .nan , 9.86851 , 11.02969 , 11.65161 ,
266
+ 12.75129 , 12.90702 , 12.83757 , np .nan , np .nan ]
267
+ }
268
+
184
269
for wt , k in zip (win_types , kwds ):
185
- vals = np .random .randn (10 )
186
- xp = cmov_window (vals , 5 , (wt ,) + tuple (k .values ()))
270
+ xp = Series (xps [wt ])
187
271
188
272
rs = mom .rolling_window (Series (vals ), 5 , wt , center = True ,
189
273
** k )
190
- assert_series_equal (Series (xp ), rs )
274
+ assert_series_equal (xp , rs )
275
+
276
+ def test_cmov_window_special_linear_range (self ):
277
+ # GH 8238
278
+ tm ._skip_if_no_scipy ()
279
+
280
+ win_types = ['kaiser' , 'gaussian' , 'general_gaussian' , 'slepian' ]
281
+ kwds = [{'beta' : 1. }, {'std' : 1. }, {'power' : 2. , 'width' : 2. },
282
+ {'width' : 0.5 }]
283
+
284
+ vals = np .array (range (10 ), dtype = np .float )
285
+ xp = vals .copy ()
286
+ xp [:2 ] = np .nan
287
+ xp [- 2 :] = np .nan
288
+ xp = Series (xp )
289
+
290
+ for wt , k in zip (win_types , kwds ):
291
+ rs = mom .rolling_window (Series (vals ), 5 , wt , center = True ,
292
+ ** k )
293
+ assert_series_equal (xp , rs )
191
294
192
295
def test_rolling_median (self ):
193
296
self ._check_moment_func (mom .rolling_median , np .median )
0 commit comments