Skip to content

Commit e477f07

Browse files
committed
add pandas to encoding tests
1 parent f1475b9 commit e477f07

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

plotly/tests/test_optional/test_utils/test_utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
from datetime import datetime as dt
66
import numpy as np
77
import json
8+
import pandas as pd
89

910
from plotly import utils
1011
from 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
1415
numeric_list = [1, 2, 3]
1516
np_list = np.array([1, 2, 3])
1617
mixed_list = [1, 'A', dt(2014, 1, 5)]
18+
pd = pd.DataFrame(columns=['col 1'], data=[1, 2, 3])
1719

1820

1921
def test_column_json_encoding():
@@ -29,10 +31,15 @@ def test_column_json_encoding():
2931

3032

3133
def 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

Comments
 (0)