@@ -158,6 +158,12 @@ def test_causal_savgol_smoother(self):
158
158
smoothed_signal = smoother .smooth (signal )
159
159
assert np .allclose (smoothed_signal , signal , equal_nan = True )
160
160
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
+
161
167
def test_impute (self ):
162
168
# test front nan error
163
169
with pytest .raises (ValueError ):
@@ -178,7 +184,7 @@ def test_impute(self):
178
184
signal = np .array ([i if i % 3 else np .nan for i in range (1 , 40 )])
179
185
# test that the non-nan values are unchanged
180
186
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 )
182
188
assert np .allclose (signal [not_nans_ixs ], smoothed_signal [not_nans_ixs ])
183
189
# test that the imputer is close to the true line
184
190
assert np .allclose (range (1 , 40 ), smoothed_signal , atol = 0.5 )
@@ -187,47 +193,41 @@ def test_impute(self):
187
193
signal = np .hstack ([np .arange (10 ), [np .nan ], np .arange (10 )])
188
194
window_length = 10
189
195
smoother = Smoother (
190
- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 1
196
+ window_length = window_length , poly_fit_degree = 1
191
197
)
192
- imputed_signal = smoother .savgol_impute (signal )
198
+ imputed_signal = smoother .impute (signal )
193
199
assert np .allclose (imputed_signal , np .hstack ([np .arange (11 ), np .arange (10 )]))
194
200
smoother = Smoother (
195
- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 2
201
+ window_length = window_length , poly_fit_degree = 2
196
202
)
197
- imputed_signal = smoother .savgol_impute (signal )
203
+ imputed_signal = smoother .impute (signal )
198
204
assert np .allclose (imputed_signal , np .hstack ([np .arange (11 ), np .arange (10 )]))
199
205
200
206
# if there are nans on the boundary, should dynamically change window
201
207
signal = np .hstack (
202
208
[np .arange (5 ), [np .nan ], np .arange (20 ), [np .nan ], np .arange (5 )]
203
209
)
204
210
smoother = Smoother (
205
- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 2
211
+ window_length = window_length , poly_fit_degree = 2
206
212
)
207
- imputed_signal = smoother .savgol_impute (signal )
213
+ imputed_signal = smoother .impute (signal )
208
214
assert np .allclose (
209
215
imputed_signal , np .hstack ([np .arange (6 ), np .arange (21 ), np .arange (5 )]),
210
216
)
211
217
212
218
# if the array begins with np.nan, we should tell the user to peel it off before sending
213
219
signal = np .hstack ([[np .nan ], np .arange (20 ), [np .nan ], np .arange (5 )])
214
220
smoother = Smoother (
215
- smoother_name = "savgol" , window_length = window_length , poly_fit_degree = 2
221
+ window_length = window_length , poly_fit_degree = 2
216
222
)
217
223
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 )
225
225
226
226
# test the boundary methods
227
227
signal = np .arange (20 )
228
- smoother = Smoother (smoother_name = "savgol" , poly_fit_degree = 0 ,
228
+ smoother = Smoother (poly_fit_degree = 0 ,
229
229
boundary_method = "identity" , window_length = 10 )
230
- smoothed_signal = smoother .savgol_impute (signal )
230
+ smoothed_signal = smoother .impute (signal )
231
231
assert np .allclose (smoothed_signal , signal )
232
232
233
233
# test that we don't hit a matrix inversion error when there are
@@ -238,6 +238,13 @@ def test_impute(self):
238
238
smoothed_signal = smoother .impute (signal )
239
239
assert np .allclose (smoothed_signal , np .hstack ([[1 ], np .ones (12 ), np .arange (5 )]))
240
240
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
+
241
248
def test_pandas_series_input (self ):
242
249
# The savgol method should match the linear regression method on the first
243
250
# window_length-many values of the signal, if the savgol_weighting is set to true,
0 commit comments