@@ -158,6 +158,12 @@ def test_causal_savgol_smoother(self):
158158 smoothed_signal = smoother .smooth (signal )
159159 assert np .allclose (smoothed_signal , signal , equal_nan = True )
160160
161+ # test window_length > len(signal) and boundary_method="identity"
162+ signal = np .arange (20 )
163+ smoother = Smoother (boundary_method = "identity" , window_length = 30 )
164+ smoothed_signal = smoother .smooth (signal )
165+ assert np .allclose (signal , smoothed_signal )
166+
161167 def test_impute (self ):
162168 # test front nan error
163169 with pytest .raises (ValueError ):
@@ -178,7 +184,7 @@ def test_impute(self):
178184 signal = np .array ([i if i % 3 else np .nan for i in range (1 , 40 )])
179185 # test that the non-nan values are unchanged
180186 not_nans_ixs = np .bitwise_xor (np .isnan (signal , where = True ), np .full (len (signal ), True ))
181- smoothed_signal = Smoother ().savgol_impute (signal )
187+ smoothed_signal = Smoother ().impute (signal )
182188 assert np .allclose (signal [not_nans_ixs ], smoothed_signal [not_nans_ixs ])
183189 # test that the imputer is close to the true line
184190 assert np .allclose (range (1 , 40 ), smoothed_signal , atol = 0.5 )
@@ -187,47 +193,41 @@ def test_impute(self):
187193 signal = np .hstack ([np .arange (10 ), [np .nan ], np .arange (10 )])
188194 window_length = 10
189195 smoother = Smoother (
190- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 1
196+ window_length = window_length , poly_fit_degree = 1
191197 )
192- imputed_signal = smoother .savgol_impute (signal )
198+ imputed_signal = smoother .impute (signal )
193199 assert np .allclose (imputed_signal , np .hstack ([np .arange (11 ), np .arange (10 )]))
194200 smoother = Smoother (
195- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 2
201+ window_length = window_length , poly_fit_degree = 2
196202 )
197- imputed_signal = smoother .savgol_impute (signal )
203+ imputed_signal = smoother .impute (signal )
198204 assert np .allclose (imputed_signal , np .hstack ([np .arange (11 ), np .arange (10 )]))
199205
200206 # if there are nans on the boundary, should dynamically change window
201207 signal = np .hstack (
202208 [np .arange (5 ), [np .nan ], np .arange (20 ), [np .nan ], np .arange (5 )]
203209 )
204210 smoother = Smoother (
205- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 2
211+ window_length = window_length , poly_fit_degree = 2
206212 )
207- imputed_signal = smoother .savgol_impute (signal )
213+ imputed_signal = smoother .impute (signal )
208214 assert np .allclose (
209215 imputed_signal , np .hstack ([np .arange (6 ), np .arange (21 ), np .arange (5 )]),
210216 )
211217
212218 # if the array begins with np.nan, we should tell the user to peel it off before sending
213219 signal = np .hstack ([[np .nan ], np .arange (20 ), [np .nan ], np .arange (5 )])
214220 smoother = Smoother (
215- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 2
221+ window_length = window_length , poly_fit_degree = 2
216222 )
217223 with pytest .raises (ValueError ):
218- imputed_signal = smoother .savgol_impute (signal )
219-
220- # test window_length > len(signal) and boundary_method="identity"
221- signal = np .arange (20 )
222- smoother = Smoother (smoother_name = "savgol" , boundary_method = "identity" , window_length = 30 )
223- smoothed_signal = smoother .smooth (signal )
224- assert np .allclose (signal , smoothed_signal )
224+ imputed_signal = smoother .impute (signal )
225225
226226 # test the boundary methods
227227 signal = np .arange (20 )
228- smoother = Smoother (smoother_name = "savgol" , poly_fit_degree = 0 ,
228+ smoother = Smoother (poly_fit_degree = 0 ,
229229 boundary_method = "identity" , window_length = 10 )
230- smoothed_signal = smoother .savgol_impute (signal )
230+ smoothed_signal = smoother .impute (signal )
231231 assert np .allclose (smoothed_signal , signal )
232232
233233 # test that we don't hit a matrix inversion error when there are
@@ -238,6 +238,13 @@ def test_impute(self):
238238 smoothed_signal = smoother .impute (signal )
239239 assert np .allclose (smoothed_signal , np .hstack ([[1 ], np .ones (12 ), np .arange (5 )]))
240240
241+ # test the impute_order argument
242+ signal = np .hstack ([[1 , np .nan , np .nan , 2 ], np .arange (5 )])
243+ smoother = Smoother ()
244+ smoothed_signal = smoother .impute (signal , impute_order = 1 )
245+ assert np .allclose (smoothed_signal , np .hstack ([[1 , 1 , 1 , 2 ], np .arange (5 )]))
246+
247+
241248 def test_pandas_series_input (self ):
242249 # The savgol method should match the linear regression method on the first
243250 # window_length-many values of the signal, if the savgol_weighting is set to true,
0 commit comments