@@ -38,7 +38,7 @@ def test_column_json_encoding():
38
38
Column (np_list , 'col 3' )
39
39
]
40
40
json_columns = json .dumps (
41
- columns , cls = utils ._plotlyJSONEncoder , sort_keys = True
41
+ columns , cls = utils .PlotlyJSONEncoder , sort_keys = True
42
42
)
43
43
assert ('[{"data": [1, 2, 3], "name": "col 1"}, '
44
44
'{"data": [1, "A", "2014-01-05", '
@@ -56,8 +56,8 @@ def test_figure_json_encoding():
56
56
data = Data ([s1 , s2 ])
57
57
figure = Figure (data = data )
58
58
59
- js1 = json .dumps (s1 , cls = utils ._plotlyJSONEncoder , sort_keys = True )
60
- js2 = json .dumps (s2 , cls = utils ._plotlyJSONEncoder , sort_keys = True )
59
+ js1 = json .dumps (s1 , cls = utils .PlotlyJSONEncoder , sort_keys = True )
60
+ js2 = json .dumps (s2 , cls = utils .PlotlyJSONEncoder , sort_keys = True )
61
61
62
62
assert (js1 == '{"type": "scatter3d", "x": [1, 2, 3], '
63
63
'"y": [1, 2, 3, NaN, NaN, Infinity, "2014-01-05"], '
@@ -66,8 +66,8 @@ def test_figure_json_encoding():
66
66
assert (js2 == '{"type": "scatter", "x": [1, 2, 3]}' )
67
67
68
68
# Test JSON encoding works
69
- json .dumps (data , cls = utils ._plotlyJSONEncoder , sort_keys = True )
70
- json .dumps (figure , cls = utils ._plotlyJSONEncoder , sort_keys = True )
69
+ json .dumps (data , cls = utils .PlotlyJSONEncoder , sort_keys = True )
70
+ json .dumps (figure , cls = utils .PlotlyJSONEncoder , sort_keys = True )
71
71
72
72
# Test data wasn't mutated
73
73
assert (bool (np .asarray (np_list ==
@@ -79,47 +79,48 @@ def test_figure_json_encoding():
79
79
80
80
81
81
def test_datetime_json_encoding ():
82
- j1 = json .dumps (dt_list , cls = utils ._plotlyJSONEncoder )
82
+ j1 = json .dumps (dt_list , cls = utils .PlotlyJSONEncoder )
83
83
assert (j1 == '["2014-01-05", '
84
84
'"2014-01-05 01:01:01", '
85
85
'"2014-01-05 01:01:01.000001"]' )
86
- j2 = json .dumps ({"x" : dt_list }, cls = utils ._plotlyJSONEncoder )
86
+ j2 = json .dumps ({"x" : dt_list }, cls = utils .PlotlyJSONEncoder )
87
87
assert (j2 == '{"x": ["2014-01-05", '
88
88
'"2014-01-05 01:01:01", '
89
89
'"2014-01-05 01:01:01.000001"]}' )
90
90
91
91
92
92
def test_pandas_json_encoding ():
93
- j1 = json .dumps (df ['col 1' ], cls = utils ._plotlyJSONEncoder )
93
+ j1 = json .dumps (df ['col 1' ], cls = utils .PlotlyJSONEncoder )
94
94
assert (j1 == '[1, 2, 3, "2014-01-05", null, NaN, Infinity]' )
95
95
96
96
# Test that data wasn't mutated
97
97
assert_series_equal (df ['col 1' ],
98
98
pd .Series ([1 , 2 , 3 , dt (2014 , 1 , 5 ),
99
99
pd .NaT , np .NaN , np .Inf ]))
100
100
101
- j2 = json .dumps (df .index , cls = utils ._plotlyJSONEncoder )
101
+ j2 = json .dumps (df .index , cls = utils .PlotlyJSONEncoder )
102
102
assert (j2 == '[0, 1, 2, 3, 4, 5, 6]' )
103
103
104
104
nat = [pd .NaT ]
105
- j3 = json .dumps (nat , cls = utils ._plotlyJSONEncoder )
105
+ j3 = json .dumps (nat , cls = utils .PlotlyJSONEncoder )
106
106
assert (j3 == '[null]' )
107
107
assert (nat [0 ] is pd .NaT )
108
108
109
- j4 = json .dumps (rng , cls = utils ._plotlyJSONEncoder )
109
+ j4 = json .dumps (rng , cls = utils .PlotlyJSONEncoder )
110
110
assert (j4 == '["2011-01-01", "2011-01-01 01:00:00"]' )
111
111
112
- j5 = json .dumps (ts , cls = utils ._plotlyJSONEncoder )
112
+ j5 = json .dumps (ts , cls = utils .PlotlyJSONEncoder )
113
113
assert (j5 == '[1.5, 2.5]' )
114
114
assert_series_equal (ts , pd .Series ([1.5 , 2.5 ], index = rng ))
115
115
116
- j6 = json .dumps (ts .index , cls = utils ._plotlyJSONEncoder )
116
+ j6 = json .dumps (ts .index , cls = utils .PlotlyJSONEncoder )
117
117
assert (j6 == '["2011-01-01", "2011-01-01 01:00:00"]' )
118
118
119
119
120
120
def test_numpy_masked_json_encoding ():
121
121
l = [1 , 2 , np .ma .core .masked ]
122
- j1 = json .dumps (l , cls = utils ._plotlyJSONEncoder )
122
+ j1 = json .dumps (l , cls = utils .PlotlyJSONEncoder )
123
+ print j1
123
124
assert (j1 == '[1, 2, NaN]' )
124
125
assert (set (l ) == set ([1 , 2 , np .ma .core .masked ]))
125
126
@@ -142,23 +143,23 @@ def test_masked_constants_example():
142
143
renderer = PlotlyRenderer ()
143
144
Exporter (renderer ).run (fig )
144
145
145
- json .dumps (renderer .plotly_fig , cls = utils ._plotlyJSONEncoder )
146
+ json .dumps (renderer .plotly_fig , cls = utils .PlotlyJSONEncoder )
146
147
147
148
jy = json .dumps (renderer .plotly_fig ['data' ][1 ]['y' ],
148
- cls = utils ._plotlyJSONEncoder )
149
+ cls = utils .PlotlyJSONEncoder )
149
150
assert (jy == '[-398.11793026999999, -398.11792966000002, '
150
151
'-398.11786308000001, NaN]' )
151
152
152
153
153
154
def test_numpy_dates ():
154
155
a = np .arange (np .datetime64 ('2011-07-11' ), np .datetime64 ('2011-07-18' ))
155
- j1 = json .dumps (a , cls = utils ._plotlyJSONEncoder )
156
+ j1 = json .dumps (a , cls = utils .PlotlyJSONEncoder )
156
157
assert (j1 == '["2011-07-11", "2011-07-12", "2011-07-13", '
157
158
'"2011-07-14", "2011-07-15", "2011-07-16", '
158
159
'"2011-07-17"]' )
159
160
160
161
161
162
def test_datetime_dot_date ():
162
163
a = [datetime .date (2014 , 1 , 1 ), datetime .date (2014 , 1 , 2 )]
163
- j1 = json .dumps (a , cls = utils ._plotlyJSONEncoder )
164
+ j1 = json .dumps (a , cls = utils .PlotlyJSONEncoder )
164
165
assert (j1 == '["2014-01-01", "2014-01-02"]' )
0 commit comments