@@ -56,6 +56,39 @@ def test_pie_like_px():
5656 _compare_figures (trace , fig )
5757
5858
59+ def test_pie_custom_category_order (constructor ):
60+ # https://github.com/plotly/plotly.py/issues/4999
61+ data = {
62+ "status" : ["On Route" , "Pending" , "Waiting Result" , "Delivered" ],
63+ "count" : [28 , 10 , 73 , 8 ],
64+ }
65+ df = constructor (data )
66+ custom_order = ["Pending" , "Waiting Result" , "On Route" , "Delivered" ]
67+ result = px .pie (
68+ data_frame = df ,
69+ values = "count" ,
70+ names = "status" ,
71+ category_orders = {"status" : custom_order },
72+ )
73+ assert list (result .to_dict ()["data" ][0 ]["labels" ]) == [
74+ "Pending" ,
75+ "Waiting Result" ,
76+ "On Route" ,
77+ "Delivered" ,
78+ ]
79+ values_ = np .array (
80+ [
81+ x [0 ]
82+ for x in sorted (
83+ zip (data ["count" ], data ["status" ]),
84+ key = lambda t : custom_order .index (t [1 ]),
85+ )
86+ ]
87+ )
88+ trace = go .Pie (values = values_ , labels = custom_order )
89+ _compare_figures (trace , result )
90+
91+
5992def test_sunburst_treemap_colorscales ():
6093 labels = ["Eve" , "Cain" , "Seth" , "Enos" , "Noam" , "Abel" , "Awan" , "Enoch" , "Azura" ]
6194 parents = ["" , "Eve" , "Eve" , "Seth" , "Seth" , "Eve" , "Eve" , "Awan" , "Eve" ]
0 commit comments