|
3 | 3 | import numpy as np |
4 | 4 | import pandas as pd |
5 | 5 | import pytest |
| 6 | +import unittest.mock as mock |
6 | 7 | from plotly.express._core import build_dataframe |
7 | 8 | from pandas.testing import assert_frame_equal |
8 | 9 |
|
@@ -233,17 +234,22 @@ def test_build_df_with_index(): |
233 | 234 | assert_frame_equal(tips.reset_index()[out["data_frame"].columns], out["data_frame"]) |
234 | 235 |
|
235 | 236 |
|
236 | | -def test_build_df_protocol(): |
237 | | - import vaex |
| 237 | +def test_build_df_using_interchange_protocol_mock(): |
| 238 | + class CustomDataFrame: |
| 239 | + def __dataframe__(self): |
| 240 | + pass |
238 | 241 |
|
239 | | - # take out the 'species' columns since there are still some issues with strings |
240 | | - iris_pandas = px.data.iris()[["petal_width", "sepal_length"]] |
241 | | - iris_vaex = vaex.from_pandas(iris_pandas) |
242 | | - args = dict(data_frame=iris_vaex, x="petal_width", y="sepal_length") |
243 | | - out = build_dataframe(args, go.Scatter) |
244 | | - assert_frame_equal( |
245 | | - iris_pandas.reset_index()[out["data_frame"].columns], out["data_frame"] |
246 | | - ) |
| 242 | + input_dataframe = CustomDataFrame() |
| 243 | + args = dict(data_frame=input_dataframe, x="petal_width", y="sepal_length") |
| 244 | + |
| 245 | + iris_pandas = px.data.iris() |
| 246 | + |
| 247 | + with mock.patch("pandas.__version__", "2.0.2"): |
| 248 | + with mock.patch( |
| 249 | + "pandas.api.interchange.from_dataframe", return_value=iris_pandas |
| 250 | + ) as mock_from_dataframe: |
| 251 | + build_dataframe(args, go.Scatter) |
| 252 | + mock_from_dataframe.assert_called_once_with(input_dataframe) |
247 | 253 |
|
248 | 254 |
|
249 | 255 | def test_timezones(): |
|
0 commit comments