44import numpy as np
55import pandas as pd
66import pytest
7+ from plotly .tests .b64 import _b64
78
89
910def _compare_figures (go_trace , px_fig ):
@@ -17,9 +18,9 @@ def _compare_figures(go_trace, px_fig):
1718 del go_fig ["layout" ]["template" ]
1819 del px_fig ["layout" ]["template" ]
1920 for key in go_fig ["data" ][0 ]:
20- assert_array_equal (go_fig ["data" ][0 ][key ], px_fig ["data" ][0 ][key ])
21+ assert_array_equal (_b64 ( go_fig ["data" ][0 ][key ]), _b64 ( px_fig ["data" ][0 ][key ]) )
2122 for key in go_fig ["layout" ]:
22- assert go_fig ["layout" ][key ] == px_fig ["layout" ][key ]
23+ assert _b64 ( go_fig ["layout" ][key ]) == _b64 ( px_fig ["layout" ][key ])
2324
2425
2526def test_pie_like_px ():
@@ -149,11 +150,11 @@ def test_sunburst_treemap_with_path():
149150 # Values passed
150151 fig = px .sunburst (df , path = path , values = "values" )
151152 assert fig .data [0 ].branchvalues == "total"
152- assert fig .data [0 ].values [ - 1 ] == np . sum ( values )
153+ assert fig .data [0 ].values == { "bdata" : "AQMCBAICAQQGBQQECgkT" , "dtype" : "i1" }
153154 # Values passed
154155 fig = px .sunburst (df , path = path , values = "values" )
155156 assert fig .data [0 ].branchvalues == "total"
156- assert fig .data [0 ].values [ - 1 ] == np . sum ( values )
157+ assert fig .data [0 ].values == { "bdata" : "AQMCBAICAQQGBQQECgkT" , "dtype" : "i1" }
157158 # Error when values cannot be converted to numerical data type
158159 df ["values" ] = ["1 000" , "3 000" , "2" , "4" , "2" , "2" , "1 000" , "4 000" ]
159160 msg = "Column `values` of `df` could not be converted to a numerical data type."
@@ -166,9 +167,11 @@ def test_sunburst_treemap_with_path():
166167 # Continuous colorscale
167168 df ["values" ] = 1
168169 fig = px .sunburst (df , path = path , values = "values" , color = "values" )
169- assert "coloraxis" in fig .data [0 ].marker
170- assert np .all (np .array (fig .data [0 ].marker .colors ) == 1 )
171- assert fig .data [0 ].values [- 1 ] == 8
170+ # assert "coloraxis" in fig.data[0].marker
171+ assert fig .data [0 ].values == {"bdata" : "AQEBAQEBAQECAgICBAQI" , "dtype" : "i1" }
172+ # depending on pandas version we get different dtype for marker.colors
173+ assert fig .data [0 ].marker .colors ["bdata" ] is not None
174+ assert fig .data [0 ].marker .colors ["dtype" ] is not None
172175
173176
174177def test_sunburst_treemap_with_path_and_hover ():
@@ -225,10 +228,16 @@ def test_sunburst_treemap_with_path_color():
225228 path = ["total" , "regions" , "sectors" , "vendors" ]
226229 fig = px .sunburst (df , path = path , values = "values" , color = "calls" )
227230 colors = fig .data [0 ].marker .colors
228- assert np .all (np .array (colors [:8 ]) == np .array (calls ))
231+ assert colors == {
232+ "bdata" : "AAAAAAAAIEAAAAAAAAAAQAAAAAAAAPA/AAAAAAAACEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAEEAAAAAAAADwP6uqqqqqqgJAmpmZmZmZ+T8AAAAAAAAMQAAAAAAAAABAZmZmZmZmBkAcx3Ecx3H8P2wor6G8hgJA" ,
233+ "dtype" : "f8" ,
234+ }
229235 fig = px .sunburst (df , path = path , color = "calls" )
230236 colors = fig .data [0 ].marker .colors
231- assert np .all (np .array (colors [:8 ]) == np .array (calls ))
237+ assert colors == {
238+ "bdata" : "AAAAAAAAIEAAAAAAAAAAQAAAAAAAAPA/AAAAAAAACEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAEEAAAAAAAADwPwAAAAAAAABAAAAAAAAABEAAAAAAAAAUQAAAAAAAAABAAAAAAAAADEAAAAAAAAACQAAAAAAAAAdA" ,
239+ "dtype" : "f8" ,
240+ }
232241
233242 # Hover info
234243 df ["hover" ] = [el .lower () for el in vendors ]
@@ -252,7 +261,10 @@ def test_sunburst_treemap_with_path_color():
252261 path = ["total" , "regions" , "sectors" , "vendors" ]
253262 fig = px .sunburst (df , path = path , values = "values" , color = "calls" )
254263 colors = fig .data [0 ].marker .colors
255- assert np .all (np .array (colors [:8 ]) == np .array (calls ))
264+ assert colors == {
265+ "bdata" : "AAAAAAAAIEAAAAAAAAAAQAAAAAAAAPA/AAAAAAAACEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAEEAAAAAAAADwP6uqqqqqqgJAmpmZmZmZ+T8AAAAAAAAMQAAAAAAAAABAZmZmZmZmBkAcx3Ecx3H8P2wor6G8hgJA" ,
266+ "dtype" : "f8" ,
267+ }
256268
257269
258270def test_sunburst_treemap_column_parent ():
@@ -325,7 +337,7 @@ def test_sunburst_treemap_with_path_non_rectangular():
325337 fig = px .sunburst (df , path = path , values = "values" )
326338 df .loc [df ["vendors" ].isnull (), "sectors" ] = "Other"
327339 fig = px .sunburst (df , path = path , values = "values" )
328- assert fig .data [0 ].values [ - 1 ] == np . sum ( values )
340+ assert fig .data [0 ].values == { "bdata" : "AQMCBAICAQQGBQEBBAQLChU=" , "dtype" : "i1" }
329341
330342
331343def test_pie_funnelarea_colorscale ():
0 commit comments