@@ -143,6 +143,12 @@ def test_causal_savgol_smoother(self):
143143 smoothed_signal = smoother .smooth (signal )
144144 assert np .allclose (smoothed_signal , signal , equal_nan = True )
145145
146+ # test window_length > len(signal) and boundary_method="identity"
147+ signal = np .arange (20 )
148+ smoother = Smoother (boundary_method = "identity" , window_length = 30 )
149+ smoothed_signal = smoother .smooth (signal )
150+ assert np .allclose (signal , smoothed_signal )
151+
146152 def test_impute (self ):
147153 # test the nan imputer
148154 signal = np .array ([i if i % 3 else np .nan for i in range (1 , 40 )])
@@ -159,7 +165,7 @@ def test_impute(self):
159165 signal = np .array ([i if i % 3 else np .nan for i in range (1 , 40 )])
160166 # test that the non-nan values are unchanged
161167 not_nans_ixs = np .bitwise_xor (np .isnan (signal , where = True ), np .full (len (signal ), True ))
162- smoothed_signal = Smoother ().savgol_impute (signal )
168+ smoothed_signal = Smoother ().impute (signal )
163169 assert np .allclose (signal [not_nans_ixs ], smoothed_signal [not_nans_ixs ])
164170 # test that the imputer is close to the true line
165171 assert np .allclose (range (1 , 40 ), smoothed_signal , atol = 0.5 )
@@ -168,49 +174,50 @@ def test_impute(self):
168174 signal = np .hstack ([np .arange (10 ), [np .nan ], np .arange (10 )])
169175 window_length = 10
170176 smoother = Smoother (
171- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 1
177+ window_length = window_length , poly_fit_degree = 1
172178 )
173- imputed_signal = smoother .savgol_impute (signal )
179+ imputed_signal = smoother .impute (signal )
174180 assert np .allclose (imputed_signal , np .hstack ([np .arange (11 ), np .arange (10 )]))
175181 smoother = Smoother (
176- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 2
182+ window_length = window_length , poly_fit_degree = 2
177183 )
178- imputed_signal = smoother .savgol_impute (signal )
184+ imputed_signal = smoother .impute (signal )
179185 assert np .allclose (imputed_signal , np .hstack ([np .arange (11 ), np .arange (10 )]))
180186
181187 # if there are nans on the boundary, should dynamically change window
182188 signal = np .hstack (
183189 [np .arange (5 ), [np .nan ], np .arange (20 ), [np .nan ], np .arange (5 )]
184190 )
185191 smoother = Smoother (
186- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 2
192+ window_length = window_length , poly_fit_degree = 2
187193 )
188- imputed_signal = smoother .savgol_impute (signal )
194+ imputed_signal = smoother .impute (signal )
189195 assert np .allclose (
190196 imputed_signal , np .hstack ([np .arange (6 ), np .arange (21 ), np .arange (5 )]),
191197 )
192198
193199 # if the array begins with np.nan, we should tell the user to peel it off before sending
194200 signal = np .hstack ([[np .nan ], np .arange (20 ), [np .nan ], np .arange (5 )])
195201 smoother = Smoother (
196- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 2
202+ window_length = window_length , poly_fit_degree = 2
197203 )
198204 with pytest .raises (ValueError ):
199- imputed_signal = smoother .savgol_impute (signal )
200-
201- # test window_length > len(signal) and boundary_method="identity"
202- signal = np .arange (20 )
203- smoother = Smoother (smoother_name = "savgol" , boundary_method = "identity" , window_length = 30 )
204- smoothed_signal = smoother .smooth (signal )
205- assert np .allclose (signal , smoothed_signal )
205+ imputed_signal = smoother .impute (signal )
206206
207207 # test the boundary methods
208208 signal = np .arange (20 )
209- smoother = Smoother (smoother_name = "savgol" , poly_fit_degree = 0 ,
209+ smoother = Smoother (poly_fit_degree = 0 ,
210210 boundary_method = "identity" , window_length = 10 )
211- smoothed_signal = smoother .savgol_impute (signal )
211+ smoothed_signal = smoother .impute (signal )
212212 assert np .allclose (smoothed_signal , signal )
213213
214+ # test the impute_order argument
215+ signal = np .hstack ([[1 , np .nan , np .nan , 2 ], np .arange (5 )])
216+ smoother = Smoother ()
217+ smoothed_signal = smoother .impute (signal , impute_order = 1 )
218+ assert np .allclose (smoothed_signal , np .hstack ([[1 , 1 , 1 , 2 ], np .arange (5 )]))
219+
220+
214221 def test_pandas_series_input (self ):
215222 # The savgol method should match the linear regression method on the first
216223 # window_length-many values of the signal, if the savgol_weighting is set to true,
0 commit comments