|
1 | 1 | import copy
|
| 2 | +import pytest |
2 | 3 | import plotly.express as px
|
3 | 4 |
|
| 5 | +""" |
| 6 | +This test is in the validators folder since copy.deepcopy ends up calling |
| 7 | +BaseFigure(*args) which hits `validate_coerce`. |
4 | 8 |
|
5 |
| -def test_deepcopy(): |
6 |
| - gapminder = px.data.gapminder() |
| 9 | +When inputs are dataframes and arrays, then the copied figure is called with |
| 10 | +base64 encoded arrays. |
| 11 | +""" |
| 12 | + |
| 13 | + |
| 14 | +@pytest.mark.parametrize("return_type", ["pandas", "polars", "pyarrow"]) |
| 15 | +@pytest.mark.filterwarnings( |
| 16 | + r"ignore:\*scattermapbox\* is deprecated! Use \*scattermap\* instead" |
| 17 | +) |
| 18 | +def test_deepcopy_dataframe(return_type): |
| 19 | + gapminder = px.data.gapminder(return_type=return_type) |
7 | 20 | fig = px.line(gapminder, x="year", y="gdpPercap", color="country")
|
| 21 | + fig_copied = copy.deepcopy(fig) |
| 22 | + |
| 23 | + assert fig_copied.to_dict() == fig.to_dict() |
| 24 | + |
| 25 | + |
| 26 | +@pytest.mark.filterwarnings( |
| 27 | + r"ignore:\*scattermapbox\* is deprecated! Use \*scattermap\* instead" |
| 28 | +) |
| 29 | +def test_deepcopy_array(): |
| 30 | + gapminder = px.data.gapminder() |
| 31 | + x = gapminder["year"].to_numpy() |
| 32 | + y = gapminder["gdpPercap"].to_numpy() |
| 33 | + color = gapminder["country"].to_numpy() |
8 | 34 |
|
9 |
| - fig_copy = copy.deepcopy(fig) |
| 35 | + fig = px.line(x=x, y=y, color=color) |
| 36 | + fig_copied = copy.deepcopy(fig) |
10 | 37 |
|
11 |
| - assert fig_copy is not None |
| 38 | + assert fig_copied.to_dict() == fig.to_dict() |
0 commit comments