4
4
import numpy as np
5
5
import pandas as pd
6
6
import pytest
7
+ from plotly .tests .b64 import _b64
7
8
8
9
9
10
def _compare_figures (go_trace , px_fig ):
@@ -17,9 +18,9 @@ def _compare_figures(go_trace, px_fig):
17
18
del go_fig ["layout" ]["template" ]
18
19
del px_fig ["layout" ]["template" ]
19
20
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 ]) )
21
22
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 ])
23
24
24
25
25
26
def test_pie_like_px ():
@@ -149,11 +150,11 @@ def test_sunburst_treemap_with_path():
149
150
# Values passed
150
151
fig = px .sunburst (df , path = path , values = "values" )
151
152
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" }
153
154
# Values passed
154
155
fig = px .sunburst (df , path = path , values = "values" )
155
156
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" }
157
158
# Error when values cannot be converted to numerical data type
158
159
df ["values" ] = ["1 000" , "3 000" , "2" , "4" , "2" , "2" , "1 000" , "4 000" ]
159
160
msg = "Column `values` of `df` could not be converted to a numerical data type."
@@ -166,9 +167,11 @@ def test_sunburst_treemap_with_path():
166
167
# Continuous colorscale
167
168
df ["values" ] = 1
168
169
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
172
175
173
176
174
177
def test_sunburst_treemap_with_path_and_hover ():
@@ -225,10 +228,16 @@ def test_sunburst_treemap_with_path_color():
225
228
path = ["total" , "regions" , "sectors" , "vendors" ]
226
229
fig = px .sunburst (df , path = path , values = "values" , color = "calls" )
227
230
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
+ }
229
235
fig = px .sunburst (df , path = path , color = "calls" )
230
236
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
+ }
232
241
233
242
# Hover info
234
243
df ["hover" ] = [el .lower () for el in vendors ]
@@ -252,7 +261,10 @@ def test_sunburst_treemap_with_path_color():
252
261
path = ["total" , "regions" , "sectors" , "vendors" ]
253
262
fig = px .sunburst (df , path = path , values = "values" , color = "calls" )
254
263
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
+ }
256
268
257
269
258
270
def test_sunburst_treemap_column_parent ():
@@ -325,7 +337,7 @@ def test_sunburst_treemap_with_path_non_rectangular():
325
337
fig = px .sunburst (df , path = path , values = "values" )
326
338
df .loc [df ["vendors" ].isnull (), "sectors" ] = "Other"
327
339
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" }
329
341
330
342
331
343
def test_pie_funnelarea_colorscale ():
0 commit comments