Skip to content

Commit a873bd9

Browse files
committed
added __init__ to test_figure_messages//typo//Py2 converts all grabbed plotly objects into json with strings, not unicode. Solves Py2 test error
1 parent 0dc1999 commit a873bd9

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

plotly/basedatatypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3175,7 +3175,7 @@ def on_change(self, callback, append=False, *args):
31753175
subproperties of this object are modified.
31763176
31773177
Callback will be invoked whenever ANY of these properties is
3178-
modified. Furthermore. The callback will only be invoked once even
3178+
modified. Furthermore, the callback will only be invoked once even
31793179
if multiple properties are modified during the same restyle /
31803180
relayout / update operation.
31813181

plotly/plotly/plotly.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,19 @@ def _swap_xy_data(data_obj):
374374
)
375375

376376

377+
def byteify(input):
378+
"""Convert unicode strings in JSON object to byte strings"""
379+
if isinstance(input, dict):
380+
return {byteify(key): byteify(value)
381+
for key, value in input.iteritems()}
382+
elif isinstance(input, list):
383+
return [byteify(element) for element in input]
384+
elif isinstance(input, unicode):
385+
return input.encode('utf-8')
386+
else:
387+
return input
388+
389+
377390
def get_figure(file_owner_or_url, file_id=None, raw=False):
378391
"""Returns a JSON figure representation for the specified file
379392
@@ -444,7 +457,8 @@ def get_figure(file_owner_or_url, file_id=None, raw=False):
444457
fid = '{}:{}'.format(file_owner, file_id)
445458
response = v2.plots.content(fid, inline_data=True)
446459
figure = response.json()
447-
460+
if six.PY2:
461+
figure = byteify(figure)
448462
# Fix 'histogramx', 'histogramy', and 'bardir' stuff
449463
for index, entry in enumerate(figure['data']):
450464
try:
@@ -481,19 +495,6 @@ def get_figure(file_owner_or_url, file_id=None, raw=False):
481495
if 'stream' in entry:
482496
del figure['data'][index]['stream']
483497

484-
# convert all unicde to string
485-
if six.PY2:
486-
for t, trace in enumerate(figure['data']):
487-
for key in trace:
488-
if isinstance(trace[key], unicode):
489-
figure['data'][t][key] = trace[key].encode('ascii',
490-
'ignore')
491-
492-
for key in figure['layout']:
493-
if isinstance(figure['layout'][key], unicode):
494-
figure['layout'][key] = figure['layout'][key].encode('ascii',
495-
'ignore')
496-
497498
if raw:
498499
return figure
499500
return tools.get_graph_obj(figure, obj_type='Figure')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

plotly/tools.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,12 +1362,10 @@ def get_graph_obj(obj, obj_type=None):
13621362
from plotly.graph_objs import graph_objs
13631363
try:
13641364
cls = getattr(graph_objs, obj_type)
1365-
print(cls)
13661365
except (AttributeError, KeyError):
13671366
raise exceptions.PlotlyError(
13681367
"'{}' is not a recognized graph_obj.".format(obj_type)
13691368
)
1370-
print(obj)
13711369
return cls(obj)
13721370

13731371

0 commit comments

Comments
 (0)