@@ -48,6 +48,75 @@ def test_rolling_count(self):
48
48
def test_rolling_mean (self ):
49
49
self ._check_moment_func (mom .rolling_mean , np .mean )
50
50
51
+ def test_cmov_mean (self ):
52
+ try :
53
+ from scikits .timeseries .lib import cmov_mean
54
+ except ImportError :
55
+ raise nose .SkipTest
56
+
57
+ vals = np .random .randn (10 )
58
+ xp = cmov_mean (vals , 5 )
59
+
60
+ rs = mom .rolling_mean (vals , 5 , center = True )
61
+ assert_almost_equal (xp .compressed (), rs [2 :- 2 ])
62
+ assert_almost_equal (xp .mask , np .isnan (rs ))
63
+
64
+ xp = Series (rs )
65
+ rs = mom .rolling_mean (Series (vals ), 5 , center = True )
66
+ assert_series_equal (xp , rs )
67
+
68
+ def test_cmov_window (self ):
69
+ try :
70
+ from scikits .timeseries .lib import cmov_window
71
+ except ImportError :
72
+ raise nose .SkipTest
73
+
74
+ vals = np .random .randn (10 )
75
+ xp = cmov_window (vals , 5 , 'boxcar' )
76
+
77
+ rs = mom .rolling_window (vals , 5 , center = True )
78
+ assert_almost_equal (xp .compressed (), rs [2 :- 2 ])
79
+ assert_almost_equal (xp .mask , np .isnan (rs ))
80
+
81
+ xp = Series (rs )
82
+ rs = mom .rolling_window (Series (vals ), 5 , center = True )
83
+ assert_series_equal (xp , rs )
84
+
85
+ def test_cmov_window_types (self ):
86
+ try :
87
+ from scikits .timeseries .lib import cmov_window
88
+ except ImportError :
89
+ raise nose .SkipTest
90
+
91
+ win_types = ['triang' , 'blackman' , 'hamming' , 'bartlett' , 'bohman' ,
92
+ 'blackmanharris' , 'nuttall' , 'barthann' ]
93
+ for wt in win_types :
94
+ vals = np .random .randn (10 )
95
+ xp = cmov_window (vals , 5 , wt )
96
+
97
+ rs = mom .rolling_window (vals , 5 , window_type = wt , center = True )
98
+ assert_almost_equal (xp .compressed (), rs [2 :- 2 ])
99
+ assert_almost_equal (xp .mask , np .isnan (rs ))
100
+
101
+ def test_cmov_special (self ):
102
+ try :
103
+ from scikits .timeseries .lib import cmov_window
104
+ except ImportError :
105
+ raise nose .SkipTest
106
+
107
+ win_types = ['kaiser' , 'gaussian' , 'general_gaussian' , 'slepian' ]
108
+ kwds = [{'beta' : 1. }, {'std' : 1. }, {'power' : 2. , 'width' : 2. },
109
+ {'width' : 2. }]
110
+
111
+ for wt , k in zip (win_types , kwds ):
112
+ vals = np .random .randn (10 )
113
+ xp = cmov_window (vals , 5 , (wt ,) + tuple (k .values ()))
114
+
115
+ rs = mom .rolling_window (vals , 5 , window_type = wt , center = True ,
116
+ ** k )
117
+ assert_almost_equal (xp .compressed (), rs [2 :- 2 ])
118
+ assert_almost_equal (xp .mask , np .isnan (rs ))
119
+
51
120
def test_rolling_median (self ):
52
121
self ._check_moment_func (mom .rolling_median , np .median )
53
122
@@ -259,16 +328,16 @@ def _check_ndarray(self, func, static_comp, window=50,
259
328
result = func (arr , 20 , center = True )
260
329
expected = func (arr , 20 )
261
330
262
- assert_almost_equal (result [0 ], expected [10 ])
331
+ assert_almost_equal (result [1 ], expected [10 ])
263
332
if fill_value is None :
264
- self .assert_ (np .isnan (result [- 10 :]).all ())
333
+ self .assert_ (np .isnan (result [- 9 :]).all ())
265
334
else :
266
- self .assert_ ((result [- 10 :] == 0 ).all ())
335
+ self .assert_ ((result [- 9 :] == 0 ).all ())
267
336
if has_min_periods :
268
337
self .assert_ (np .isnan (expected [23 ]))
269
- self .assert_ (np .isnan (result [13 ]))
338
+ self .assert_ (np .isnan (result [14 ]))
270
339
self .assert_ (np .isnan (expected [- 5 ]))
271
- self .assert_ (np .isnan (result [- 15 ]))
340
+ self .assert_ (np .isnan (result [- 14 ]))
272
341
273
342
def _check_structures (self , func , static_comp ,
274
343
has_min_periods = True , has_time_rule = True ,
@@ -309,17 +378,17 @@ def _check_structures(self, func, static_comp,
309
378
if has_center :
310
379
if has_min_periods :
311
380
minp = 10
312
- series_xp = func (self .series , 25 , min_periods = minp ).shift (- 13 )
313
- frame_xp = func (self .frame , 25 , min_periods = minp ).shift (- 13 )
381
+ series_xp = func (self .series , 25 , min_periods = minp ).shift (- 12 )
382
+ frame_xp = func (self .frame , 25 , min_periods = minp ).shift (- 12 )
314
383
315
384
series_rs = func (self .series , 25 , min_periods = minp ,
316
385
center = True )
317
386
frame_rs = func (self .frame , 25 , min_periods = minp ,
318
387
center = True )
319
388
320
389
else :
321
- series_xp = func (self .series , 25 ).shift (- 13 )
322
- frame_xp = func (self .frame , 25 ).shift (- 13 )
390
+ series_xp = func (self .series , 25 ).shift (- 12 )
391
+ frame_xp = func (self .frame , 25 ).shift (- 12 )
323
392
324
393
series_rs = func (self .series , 25 , center = True )
325
394
frame_rs = func (self .frame , 25 , center = True )
0 commit comments