12
12
isna ,
13
13
)
14
14
import pandas ._testing as tm
15
+ from pandas .util .version import Version
15
16
16
17
17
18
@pytest .fixture (
@@ -778,7 +779,8 @@ def test_interp_non_timedelta_index(self, interp_methods_ind, ind):
778
779
with pytest .raises (ValueError , match = expected_error ):
779
780
df [0 ].interpolate (method = method , ** kwargs )
780
781
781
- def test_interpolate_timedelta_index (self , interp_methods_ind ):
782
+ @td .skip_if_no_scipy
783
+ def test_interpolate_timedelta_index (self , request , interp_methods_ind ):
782
784
"""
783
785
Tests for non numerical index types - object, period, timedelta
784
786
Note that all methods except time, index, nearest and values
@@ -789,17 +791,19 @@ def test_interpolate_timedelta_index(self, interp_methods_ind):
789
791
df = pd .DataFrame ([0 , 1 , np .nan , 3 ], index = ind )
790
792
791
793
method , kwargs = interp_methods_ind
792
- if method == "pchip" :
793
- pytest .importorskip ("scipy" )
794
-
795
- if method in {"linear" , "pchip" }:
796
- result = df [0 ].interpolate (method = method , ** kwargs )
797
- expected = Series ([0.0 , 1.0 , 2.0 , 3.0 ], name = 0 , index = ind )
798
- tm .assert_series_equal (result , expected )
799
- else :
800
- pytest .skip (
801
- "This interpolation method is not supported for Timedelta Index yet."
794
+ import scipy
795
+
796
+ if method in {"cubic" , "zero" } or (
797
+ method == "barycentric" and Version (scipy .__version__ ) < Version ("1.5.0" )
798
+ ):
799
+ request .node .add_marker (
800
+ pytest .mark .xfail (
801
+ reason = f"{ method } interpolation is not supported for TimedeltaIndex"
802
+ )
802
803
)
804
+ result = df [0 ].interpolate (method = method , ** kwargs )
805
+ expected = Series ([0.0 , 1.0 , 2.0 , 3.0 ], name = 0 , index = ind )
806
+ tm .assert_series_equal (result , expected )
803
807
804
808
@pytest .mark .parametrize (
805
809
"ascending, expected_values" ,
0 commit comments