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 ():
@@ -29,10 +31,15 @@ def test_column_json_encoding():
2931
3032
3133def test_figure_json_encoding ():
32- s = Scatter3d (x = numeric_list , y = np_list , z = mixed_list )
33- data = Data ([s ])
34+ s1 = Scatter3d (x = numeric_list , y = np_list , z = mixed_list )
35+ s2 = Scatter (x = pd ['col 1' ])
36+ data = Data ([s1 , s2 ])
3437 figure = Figure (data = data )
3538
36- json .dumps (s , cls = utils ._plotlyJSONEncoder )
39+ js1 = json .dumps (s1 , cls = utils ._plotlyJSONEncoder )
40+ js2 = json .dumps (s2 , cls = utils ._plotlyJSONEncoder )
41+ assert (js1 == '{"y": [1, 2, 3], "x": [1, 2, 3], "z": '
42+ '[1, "A", "2014-01-05"], "type": "scatter3d"}' )
43+ assert (js2 == '{"x": [1, 2, 3], "type": "scatter"}' )
3744 json .dumps (data , cls = utils ._plotlyJSONEncoder )
3845 json .dumps (figure , cls = utils ._plotlyJSONEncoder )
0 commit comments