55from datetime import datetime as dt
66import numpy as np
77import json
8+ import pandas as pd
89
910from plotly import utils
1011from plotly .grid_objs import Column
11- from plotly .graph_objs import Scatter3d , Figure , Data
12+ from plotly .graph_objs import Scatter , Scatter3d , Figure , Data
1213
1314## JSON encoding
1415numeric_list = [1 , 2 , 3 ]
1516np_list = np .array ([1 , 2 , 3 ])
1617mixed_list = [1 , 'A' , dt (2014 , 1 , 5 )]
18+ pd = pd .DataFrame (columns = ['col 1' ], data = [1 , 2 , 3 ])
1719
1820
1921def test_column_json_encoding ():
@@ -31,10 +33,16 @@ def test_column_json_encoding():
3133
3234
3335def test_figure_json_encoding ():
34- s = Scatter3d (x = numeric_list , y = np_list , z = mixed_list )
35- data = Data ([s ])
36+ s1 = Scatter3d (x = numeric_list , y = np_list , z = mixed_list )
37+ s2 = Scatter (x = pd ['col 1' ])
38+ data = Data ([s1 , s2 ])
3639 figure = Figure (data = data )
3740
38- json .dumps (s , cls = utils ._plotlyJSONEncoder )
39- json .dumps (data , cls = utils ._plotlyJSONEncoder )
40- json .dumps (figure , cls = utils ._plotlyJSONEncoder )
41+ js1 = json .dumps (s1 , cls = utils ._plotlyJSONEncoder , sort_keys = True )
42+ js2 = json .dumps (s2 , cls = utils ._plotlyJSONEncoder , sort_keys = True )
43+
44+ assert (js1 == '{"type": "scatter3d", "x": [1, 2, 3], ' +
45+ '"y": [1, 2, 3], "z": [1, "A", "2014-01-05"]}' )
46+ assert (js2 == '{"type": "scatter", "x": [1, 2, 3]}' )
47+ json .dumps (data , cls = utils ._plotlyJSONEncoder , sort_keys = True )
48+ json .dumps (figure , cls = utils ._plotlyJSONEncoder , sort_keys = True )
0 commit comments