Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c1d326

Browse files
committed
add equality test, multiple frames and numpy arrays
1 parent b07c1a3 commit 9c1d326

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed
Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
import copy
2+
import pytest
23
import plotly.express as px
34

5+
"""
6+
This test is in the validators folder since copy.deepcopy ends up calling
7+
BaseFigure(*args) which hits `validate_coerce`.
48
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)
720
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()
834

9-
fig_copy = copy.deepcopy(fig)
35+
fig = px.line(x=x, y=y, color=color)
36+
fig_copied = copy.deepcopy(fig)
1037

11-
assert fig_copy is not None
38+
assert fig_copied.to_dict() == fig.to_dict()

0 commit comments

Comments
 (0)