Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac28f7e

Browse files
committed
Rename _plotlyJSONEncoder -> PlotlyJSONEncoder.
1 parent 237c799 commit ac28f7e

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

plotly/grid_objs/grid_objs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, data, name):
6767

6868
def __str__(self):
6969
max_chars = 10
70-
jdata = json.dumps(self.data, cls=utils._plotlyJSONEncoder)
70+
jdata = json.dumps(self.data, cls=utils.PlotlyJSONEncoder)
7171
if len(jdata) > max_chars:
7272
data_string = jdata[:max_chars] + "...]"
7373
else:

plotly/plotly/plotly.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def write(self, trace, layout=None, validate=True,
536536
stream_object.update(dict(layout=layout))
537537

538538
# TODO: allow string version of this?
539-
jdata = json.dumps(stream_object, cls=utils._plotlyJSONEncoder)
539+
jdata = json.dumps(stream_object, cls=utils.PlotlyJSONEncoder)
540540
jdata += "\n"
541541

542542
try:
@@ -602,7 +602,7 @@ def get(figure_or_data, format='png', width=None, height=None):
602602

603603
url = get_config()['plotly_domain'] + "/apigenimage/"
604604
res = requests.post(
605-
url, data=json.dumps(payload, cls=utils._plotlyJSONEncoder),
605+
url, data=json.dumps(payload, cls=utils.PlotlyJSONEncoder),
606606
headers=headers, verify=get_config()['plotly_ssl_verification']
607607
)
608608

@@ -824,7 +824,7 @@ def upload(cls, grid, filename,
824824

825825
payload = {
826826
'filename': filename,
827-
'data': json.dumps(grid_json, cls=utils._plotlyJSONEncoder),
827+
'data': json.dumps(grid_json, cls=utils.PlotlyJSONEncoder),
828828
'world_readable': world_readable
829829
}
830830

@@ -905,7 +905,7 @@ def append_columns(cls, columns, grid=None, grid_url=None):
905905
raise exceptions.InputError(err)
906906

907907
payload = {
908-
'cols': json.dumps(columns, cls=utils._plotlyJSONEncoder)
908+
'cols': json.dumps(columns, cls=utils.PlotlyJSONEncoder)
909909
}
910910

911911
api_url = _api_v2.api_url('grids')+'/{grid_id}/col'.format(grid_id=grid_id)
@@ -980,7 +980,7 @@ def append_rows(cls, rows, grid=None, grid_url=None):
980980
'column' if n_columns == 1 else 'columns'))
981981

982982
payload = {
983-
'rows': json.dumps(rows, cls=utils._plotlyJSONEncoder)
983+
'rows': json.dumps(rows, cls=utils.PlotlyJSONEncoder)
984984
}
985985

986986
api_url = (_api_v2.api_url('grids')+
@@ -1098,7 +1098,7 @@ def upload(cls, meta, grid=None, grid_url=None):
10981098
grid_id = _api_v2.parse_grid_id_args(grid, grid_url)
10991099

11001100
payload = {
1101-
'metadata': json.dumps(meta, cls=utils._plotlyJSONEncoder)
1101+
'metadata': json.dumps(meta, cls=utils.PlotlyJSONEncoder)
11021102
}
11031103

11041104
api_url = _api_v2.api_url('grids')+'/{grid_id}'.format(grid_id=grid_id)
@@ -1206,14 +1206,14 @@ def _send_to_plotly(figure, **plot_options):
12061206
"""
12071207
fig = tools._replace_newline(figure) # does not mutate figure
12081208
data = json.dumps(fig['data'] if 'data' in fig else [],
1209-
cls=utils._plotlyJSONEncoder)
1209+
cls=utils.PlotlyJSONEncoder)
12101210
username, api_key = _get_session_username_and_key()
12111211
kwargs = json.dumps(dict(filename=plot_options['filename'],
12121212
fileopt=plot_options['fileopt'],
12131213
world_readable=plot_options['world_readable'],
12141214
layout=fig['layout'] if 'layout' in fig
12151215
else {}),
1216-
cls=utils._plotlyJSONEncoder)
1216+
cls=utils.PlotlyJSONEncoder)
12171217

12181218

12191219
payload = dict(platform='python', # TODO: It'd be cool to expose the platform for RaspPi and others

plotly/tests/test_optional/test_utils/test_utils.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_column_json_encoding():
3838
Column(np_list, 'col 3')
3939
]
4040
json_columns = json.dumps(
41-
columns, cls=utils._plotlyJSONEncoder, sort_keys=True
41+
columns, cls=utils.PlotlyJSONEncoder, sort_keys=True
4242
)
4343
assert('[{"data": [1, 2, 3], "name": "col 1"}, '
4444
'{"data": [1, "A", "2014-01-05", '
@@ -56,8 +56,8 @@ def test_figure_json_encoding():
5656
data = Data([s1, s2])
5757
figure = Figure(data=data)
5858

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)
6161

6262
assert(js1 == '{"type": "scatter3d", "x": [1, 2, 3], '
6363
'"y": [1, 2, 3, NaN, NaN, Infinity, "2014-01-05"], '
@@ -66,8 +66,8 @@ def test_figure_json_encoding():
6666
assert(js2 == '{"type": "scatter", "x": [1, 2, 3]}')
6767

6868
# 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)
7171

7272
# Test data wasn't mutated
7373
assert(bool(np.asarray(np_list ==
@@ -79,47 +79,48 @@ def test_figure_json_encoding():
7979

8080

8181
def test_datetime_json_encoding():
82-
j1 = json.dumps(dt_list, cls=utils._plotlyJSONEncoder)
82+
j1 = json.dumps(dt_list, cls=utils.PlotlyJSONEncoder)
8383
assert(j1 == '["2014-01-05", '
8484
'"2014-01-05 01:01:01", '
8585
'"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)
8787
assert(j2 == '{"x": ["2014-01-05", '
8888
'"2014-01-05 01:01:01", '
8989
'"2014-01-05 01:01:01.000001"]}')
9090

9191

9292
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)
9494
assert(j1 == '[1, 2, 3, "2014-01-05", null, NaN, Infinity]')
9595

9696
# Test that data wasn't mutated
9797
assert_series_equal(df['col 1'],
9898
pd.Series([1, 2, 3, dt(2014, 1, 5),
9999
pd.NaT, np.NaN, np.Inf]))
100100

101-
j2 = json.dumps(df.index, cls=utils._plotlyJSONEncoder)
101+
j2 = json.dumps(df.index, cls=utils.PlotlyJSONEncoder)
102102
assert(j2 == '[0, 1, 2, 3, 4, 5, 6]')
103103

104104
nat = [pd.NaT]
105-
j3 = json.dumps(nat, cls=utils._plotlyJSONEncoder)
105+
j3 = json.dumps(nat, cls=utils.PlotlyJSONEncoder)
106106
assert(j3 == '[null]')
107107
assert(nat[0] is pd.NaT)
108108

109-
j4 = json.dumps(rng, cls=utils._plotlyJSONEncoder)
109+
j4 = json.dumps(rng, cls=utils.PlotlyJSONEncoder)
110110
assert(j4 == '["2011-01-01", "2011-01-01 01:00:00"]')
111111

112-
j5 = json.dumps(ts, cls=utils._plotlyJSONEncoder)
112+
j5 = json.dumps(ts, cls=utils.PlotlyJSONEncoder)
113113
assert(j5 == '[1.5, 2.5]')
114114
assert_series_equal(ts, pd.Series([1.5, 2.5], index=rng))
115115

116-
j6 = json.dumps(ts.index, cls=utils._plotlyJSONEncoder)
116+
j6 = json.dumps(ts.index, cls=utils.PlotlyJSONEncoder)
117117
assert(j6 == '["2011-01-01", "2011-01-01 01:00:00"]')
118118

119119

120120
def test_numpy_masked_json_encoding():
121121
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
123124
assert(j1 == '[1, 2, NaN]')
124125
assert(set(l) == set([1, 2, np.ma.core.masked]))
125126

@@ -142,23 +143,23 @@ def test_masked_constants_example():
142143
renderer = PlotlyRenderer()
143144
Exporter(renderer).run(fig)
144145

145-
json.dumps(renderer.plotly_fig, cls=utils._plotlyJSONEncoder)
146+
json.dumps(renderer.plotly_fig, cls=utils.PlotlyJSONEncoder)
146147

147148
jy = json.dumps(renderer.plotly_fig['data'][1]['y'],
148-
cls=utils._plotlyJSONEncoder)
149+
cls=utils.PlotlyJSONEncoder)
149150
assert(jy == '[-398.11793026999999, -398.11792966000002, '
150151
'-398.11786308000001, NaN]')
151152

152153

153154
def test_numpy_dates():
154155
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)
156157
assert(j1 == '["2011-07-11", "2011-07-12", "2011-07-13", '
157158
'"2011-07-14", "2011-07-15", "2011-07-16", '
158159
'"2011-07-17"]')
159160

160161

161162
def test_datetime_dot_date():
162163
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)
164165
assert(j1 == '["2014-01-01", "2014-01-02"]')

plotly/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ class NotEncodable(Exception):
9696
pass
9797

9898

99-
class _plotlyJSONEncoder(json.JSONEncoder):
10099
def numpyJSONEncoder(self, obj):
101100
if not _numpy_imported:
102101
raise NotEncodable
102+
class PlotlyJSONEncoder(json.JSONEncoder):
103103

104104
if obj is numpy.ma.core.masked:
105105
return float('nan')

0 commit comments

Comments
 (0)