|
8 | 8 | from plotly.express._core import build_dataframe
|
9 | 9 | from pandas.testing import assert_frame_equal
|
10 | 10 |
|
| 11 | + |
11 | 12 | # Fixtures
|
12 | 13 | # --------
|
13 | 14 | @pytest.fixture
|
@@ -292,9 +293,10 @@ def __dataframe__(self):
|
292 | 293 | ) as mock_from_dataframe:
|
293 | 294 | build_dataframe(args, go.Scatter)
|
294 | 295 | mock_from_dataframe.assert_called_once_with(interchange_dataframe_reduced)
|
295 |
| - interchange_dataframe.select_columns_by_name.assert_called_with( |
296 |
| - ["petal_width", "sepal_length"] |
297 |
| - ) |
| 296 | + assert set(interchange_dataframe.select_columns_by_name.call_args[0][0]) == { |
| 297 | + "petal_width", |
| 298 | + "sepal_length", |
| 299 | + } |
298 | 300 |
|
299 | 301 | args = dict(data_frame=input_dataframe_reduced, color=None)
|
300 | 302 | with mock.patch(
|
@@ -327,6 +329,35 @@ def test_build_df_from_vaex_and_polars(test_lib):
|
327 | 329 | )
|
328 | 330 |
|
329 | 331 |
|
| 332 | +@pytest.mark.skipif( |
| 333 | + version.parse(pd.__version__) < version.parse("2.0.2"), |
| 334 | + reason="plotly doesn't use a dataframe interchange protocol for pandas < 2.0.2", |
| 335 | +) |
| 336 | +@pytest.mark.parametrize("test_lib", ["vaex", "polars"]) |
| 337 | +@pytest.mark.parametrize( |
| 338 | + "hover_data", [["sepal_width"], {"sepal_length": False, "sepal_width": ":.2f"}] |
| 339 | +) |
| 340 | +def test_build_df_with_hover_data_from_vaex_and_polars(test_lib, hover_data): |
| 341 | + if test_lib == "vaex": |
| 342 | + import vaex as lib |
| 343 | + else: |
| 344 | + import polars as lib |
| 345 | + |
| 346 | + # take out the 'species' columns since the vaex implementation does not cover strings yet |
| 347 | + iris_pandas = px.data.iris()[["petal_width", "sepal_length", "sepal_width"]] |
| 348 | + iris_vaex = lib.from_pandas(iris_pandas) |
| 349 | + args = dict( |
| 350 | + data_frame=iris_vaex, |
| 351 | + x="petal_width", |
| 352 | + y="sepal_length", |
| 353 | + hover_data=hover_data, |
| 354 | + ) |
| 355 | + out = build_dataframe(args, go.Scatter) |
| 356 | + assert_frame_equal( |
| 357 | + iris_pandas.reset_index()[out["data_frame"].columns], out["data_frame"] |
| 358 | + ) |
| 359 | + |
| 360 | + |
330 | 361 | def test_timezones():
|
331 | 362 | df = pd.DataFrame({"date": ["2015-04-04 19:31:30+1:00"], "value": [3]})
|
332 | 363 | df["date"] = pd.to_datetime(df["date"])
|
|
0 commit comments