diff --git a/packages/python/plotly/plotly/tests/test_optional/test_px/test_px_input.py b/packages/python/plotly/plotly/tests/test_optional/test_px/test_px_input.py index eb0dfd63f9..db8f733c51 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_px/test_px_input.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_px/test_px_input.py @@ -7,6 +7,18 @@ from plotly.express._core import build_dataframe from pandas.testing import assert_frame_equal +# Fixtures +# -------- +@pytest.fixture +def add_interchange_module_for_old_pandas(): + if not hasattr(pd.api, "interchange"): + pd.api.interchange = mock.MagicMock() + # to make the following import work: `import pandas.api.interchange` + with mock.patch.dict("sys.modules", {"pandas.api.interchange": pd.api.interchange}): + yield + else: + yield + def test_numpy(): fig = px.scatter(x=[1, 2, 3], y=[2, 3, 4], color=[1, 3, 9]) @@ -234,7 +246,7 @@ def test_build_df_with_index(): assert_frame_equal(tips.reset_index()[out["data_frame"].columns], out["data_frame"]) -def test_build_df_using_interchange_protocol_mock(): +def test_build_df_using_interchange_protocol_mock(add_interchange_module_for_old_pandas): class CustomDataFrame: def __dataframe__(self): pass