@@ -123,20 +123,20 @@ def test_resample_interpolate_regular_sampling_off_grid(
123123 ser = Series (np .arange (5.0 ), index )
124124
125125 method = all_1d_no_arg_interpolation_methods
126- # Resample to 1 hour sampling and interpolate with the given method
127- ser_resampled = ser . resample ( "1h" ). interpolate ( method )
128-
129- # Check that none of the resampled values are NaN, except the first one
130- # which lies 1 minute before the first actual data point
131- assert np .isnan ( ser_resampled . iloc [ 0 ])
132- assert not ser_resampled . iloc [ 1 :]. isna (). any ()
133-
134- if method not in [ "nearest" , "zero" ] :
135- # Check that the resampled values are close to the expected values
136- # except for methods with known inaccuracies
137- assert np . all (
138- np . isclose ( ser_resampled . values [ 1 :], np . arange ( 0.5 , 4.5 , 0.5 ), rtol = 1.0e-1 )
139- )
126+ result = ser . resample ( "1h" ). interpolate ( method )
127+
128+ if method == "linear" :
129+ values = np . repeat ( np . arange ( 0.0 , 4.0 ), 2 ) + np . tile ([ 1 / 3 , 2 / 3 ], 4 )
130+ elif method == "nearest" :
131+ values = np .repeat ( np . arange ( 0.0 , 5.0 ), 2 )[ 1 : - 1 ]
132+ elif method == "zero" :
133+ values = np . repeat ( np . arange ( 0.0 , 4.0 ), 2 )
134+ else :
135+ values = 0.491667 + np . arange ( 0.0 , 4.0 , 0.5 )
136+ values = np . insert ( values , 0 , np . nan )
137+ index = date_range ( "2000-01-01 00:00:00" , periods = 9 , freq = "1h" )
138+ expected = Series ( values , index = index )
139+ tm . assert_series_equal ( result , expected )
140140
141141
142142def test_resample_interpolate_irregular_sampling (all_1d_no_arg_interpolation_methods ):
0 commit comments