66from itertools import permutations
77
88
9- def test_scatter (constructor ):
10- data = px .data .iris ().to_dict (orient = "list" )
11- iris = nw .from_native (constructor (data ))
9+ def test_scatter (backend ):
10+ iris = nw .from_native (px .data .iris (return_type = backend ))
1211 fig = px .scatter (iris .to_native (), x = "sepal_width" , y = "sepal_length" )
1312 assert fig .data [0 ].type == "scatter"
1413 assert np .all (fig .data [0 ].x == iris .get_column ("sepal_width" ).to_numpy ())
@@ -17,9 +16,8 @@ def test_scatter(constructor):
1716 assert fig .data [0 ].mode == "markers"
1817
1918
20- def test_custom_data_scatter (constructor ):
21- data = px .data .iris ().to_dict (orient = "list" )
22- iris = nw .from_native (constructor (data ))
19+ def test_custom_data_scatter (backend ):
20+ iris = nw .from_native (px .data .iris (return_type = backend ))
2321 # No hover, no custom data
2422 fig = px .scatter (
2523 iris .to_native (), x = "sepal_width" , y = "sepal_length" , color = "species"
@@ -67,9 +65,8 @@ def test_custom_data_scatter(constructor):
6765 )
6866
6967
70- def test_labels (constructor ):
71- data = px .data .tips ().to_dict (orient = "list" )
72- tips = nw .from_native (constructor (data ))
68+ def test_labels (backend ):
69+ tips = nw .from_native (px .data .tips (return_type = backend ))
7370 fig = px .scatter (
7471 tips .to_native (),
7572 x = "total_bill" ,
@@ -100,10 +97,8 @@ def test_labels(constructor):
10097 ({"text" : "continent" }, "lines+markers+text" ),
10198 ],
10299)
103- def test_line_mode (constructor , extra_kwargs , expected_mode ):
104- data = px .data .gapminder ().to_dict (orient = "list" )
105- gapminder = constructor (data )
106-
100+ def test_line_mode (backend , extra_kwargs , expected_mode ):
101+ gapminder = px .data .gapminder (return_type = backend )
107102 fig = px .line (
108103 gapminder ,
109104 x = "year" ,
@@ -114,12 +109,11 @@ def test_line_mode(constructor, extra_kwargs, expected_mode):
114109 assert fig .data [0 ].mode == expected_mode
115110
116111
117- def test_px_templates (constructor ):
112+ def test_px_templates (backend ):
118113 try :
119114 import plotly .graph_objects as go
120115
121- data = px .data .tips ().to_dict (orient = "list" )
122- tips = constructor (data )
116+ tips = px .data .tips (return_type = backend )
123117
124118 # use the normal defaults
125119 fig = px .scatter ()
@@ -245,12 +239,11 @@ def test_px_defaults():
245239 pio .templates .default = "plotly"
246240
247241
248- def assert_orderings (constructor , days_order , days_check , times_order , times_check ):
242+ def assert_orderings (backend , days_order , days_check , times_order , times_check ):
249243 symbol_sequence = ["circle" , "diamond" , "square" , "cross" , "circle" , "diamond" ]
250244 color_sequence = ["red" , "blue" , "red" , "blue" , "red" , "blue" , "red" , "blue" ]
251245
252- data = px .data .tips ().to_dict (orient = "list" )
253- tips = nw .from_native (constructor (data ))
246+ tips = nw .from_native (px .data .tips (return_type = backend ))
254247
255248 fig = px .scatter (
256249 tips .to_native (),
@@ -284,16 +277,16 @@ def assert_orderings(constructor, days_order, days_check, times_order, times_che
284277
285278@pytest .mark .parametrize ("days" , permutations (["Sun" , "Sat" , "Fri" , "x" ]))
286279@pytest .mark .parametrize ("times" , permutations (["Lunch" , "x" ]))
287- def test_orthogonal_and_missing_orderings (constructor , days , times ):
280+ def test_orthogonal_and_missing_orderings (backend , days , times ):
288281 assert_orderings (
289- constructor , days , list (days ) + ["Thur" ], times , list (times ) + ["Dinner" ]
282+ backend , days , list (days ) + ["Thur" ], times , list (times ) + ["Dinner" ]
290283 )
291284
292285
293286@pytest .mark .parametrize ("days" , permutations (["Sun" , "Sat" , "Fri" , "Thur" ]))
294287@pytest .mark .parametrize ("times" , permutations (["Lunch" , "Dinner" ]))
295- def test_orthogonal_orderings (constructor , days , times ):
296- assert_orderings (constructor , days , days , times , times )
288+ def test_orthogonal_orderings (backend , days , times ):
289+ assert_orderings (backend , days , days , times , times )
297290
298291
299292def test_permissive_defaults ():
@@ -302,9 +295,8 @@ def test_permissive_defaults():
302295 px .defaults .should_not_work = "test"
303296
304297
305- def test_marginal_ranges (constructor ):
306- data = px .data .tips ().to_dict (orient = "list" )
307- df = constructor (data )
298+ def test_marginal_ranges (backend ):
299+ df = px .data .tips (return_type = backend )
308300 fig = px .scatter (
309301 df ,
310302 x = "total_bill" ,
@@ -318,9 +310,8 @@ def test_marginal_ranges(constructor):
318310 assert fig .layout .yaxis3 .range is None
319311
320312
321- def test_render_mode (constructor ):
322- data = px .data .gapminder ().to_dict (orient = "list" )
323- df = nw .from_native (constructor (data ))
313+ def test_render_mode (backend ):
314+ df = nw .from_native (px .data .gapminder (return_type = backend ))
324315 df2007 = df .filter (nw .col ("year" ) == 2007 )
325316
326317 fig = px .scatter (df2007 .to_native (), x = "gdpPercap" , y = "lifeExp" , trendline = "ols" )
0 commit comments