@@ -325,7 +325,8 @@ def test_diff_method(diff_method_and_params, test_func_and_deriv, request): # re
325325 (kerneldiff , {'kernel' : 'gaussian' , 'window_size' : 5 }),
326326 (butterdiff , {'filter_order' : 3 , 'cutoff_freq' : 1 - 1e-6 }),
327327 (finitediff , {}),
328- (savgoldiff , {'degree' : 3 , 'window_size' : 11 , 'smoothing_win' : 3 })
328+ (savgoldiff , {'degree' : 3 , 'window_size' : 11 , 'smoothing_win' : 3 }),
329+ (rtsdiff , {'order' :2 , 'log_qr_ratio' :7 , 'forwardbackward' :True })
329330]
330331
331332# Similar to the error_bounds table, index by method first. But then we test against only one 2D function,
@@ -336,7 +337,8 @@ def test_diff_method(diff_method_and_params, test_func_and_deriv, request): # re
336337 kerneldiff : [(2 , 1 ), (3 , 2 )],
337338 butterdiff : [(0 , - 1 ), (1 , - 1 )],
338339 finitediff : [(0 , - 1 ), (1 , - 1 )],
339- savgoldiff : [(0 , - 1 ), (1 , 1 )]
340+ savgoldiff : [(0 , - 1 ), (1 , 1 )],
341+ rtsdiff : [(1 , - 1 ), (1 , 0 )]
340342}
341343
342344@mark .parametrize ("multidim_method_and_params" , multidim_methods_and_params )
@@ -390,3 +392,23 @@ def test_multidimensionality(multidim_method_and_params, request):
390392 ax3 .plot_wireframe (T1 , T2 , computed_laplacian , label = 'computed' )
391393 legend = ax3 .legend (bbox_to_anchor = (0.7 , 0.8 )); legend .legend_handles [0 ].set_facecolor (pyplot .cm .viridis (0.6 ))
392394 fig .suptitle (f'{ diff_method .__name__ } ' , fontsize = 16 )
395+
396+ # List of methods that can handle missing values
397+ nan_methods_and_params = [
398+ (splinediff , {'degree' : 5 , 's' : 2 }),
399+ (polydiff , {'degree' : 2 , 'window_size' : 3 }),
400+ (rtsdiff , {'order' : 2 , 'log_qr_ratio' : 7 , 'forwardbackward' : True }),
401+ (robustdiff , {'order' : 3 , 'log_q' : 7 , 'log_r' : 2 }),
402+ ]
403+
404+ @mark .parametrize ("diff_method_and_params" , nan_methods_and_params )
405+ def test_missing_data (diff_method_and_params ):
406+ """Ensure methods that support missing data return finite outputs when NaN values are present"""
407+ diff_method , params = diff_method_and_params
408+
409+ x_nan = np .sin (t )
410+ x_nan [[5 , 10 , 15 , 20 ]] = np .nan # introduce missing data at several locations
411+ x_hat , dxdt_hat = diff_method (x_nan , dt , ** params )
412+
413+ assert np .all (np .isfinite (x_hat ))
414+ assert np .all (np .isfinite (dxdt_hat ))
0 commit comments