Skip to content

Commit 8a0fb40

Browse files
authored
Backport PR #45731: TST: Add @td.skip_if_no_scipy to failing test (#45739)
1 parent 8eb356a commit 8a0fb40

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

pandas/tests/series/methods/test_interpolate.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
isna,
1313
)
1414
import pandas._testing as tm
15+
from pandas.util.version import Version
1516

1617

1718
@pytest.fixture(
@@ -778,7 +779,8 @@ def test_interp_non_timedelta_index(self, interp_methods_ind, ind):
778779
with pytest.raises(ValueError, match=expected_error):
779780
df[0].interpolate(method=method, **kwargs)
780781

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):
782784
"""
783785
Tests for non numerical index types - object, period, timedelta
784786
Note that all methods except time, index, nearest and values
@@ -789,17 +791,19 @@ def test_interpolate_timedelta_index(self, interp_methods_ind):
789791
df = pd.DataFrame([0, 1, np.nan, 3], index=ind)
790792

791793
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+
)
802803
)
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)
803807

804808
@pytest.mark.parametrize(
805809
"ascending, expected_values",

0 commit comments

Comments
 (0)