Skip to content

Commit 5536194

Browse files
committed
Merge branch 'master' into revamp-get_subplots
Conflicts: plotly/version.py
2 parents 3ac711f + 6638801 commit 5536194

File tree

8 files changed

+328
-106
lines changed

8 files changed

+328
-106
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: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def get_figure(file_owner_or_url, file_id=None, raw=False):
369369
verify=get_config()['plotly_ssl_verification'])
370370
if response.status_code == 200:
371371
if six.PY3:
372-
content = json.loads(response.content.decode('unicode_escape'))
372+
content = json.loads(response.content.decode('utf-8'))
373373
else:
374374
content = json.loads(response.content)
375375
response_payload = content['payload']
@@ -406,14 +406,15 @@ class Stream:
406406
Stream example:
407407
# Initialize a streaming graph
408408
# by embedding stream_id's in the graph's traces
409-
>>> stream_id = "your_stream_id" # See {plotly_domain}/settings
410-
>>> py.plot(Data([Scatter(x=[],
411-
y=[],
412-
stream=dict(token=stream_id, maxpoints=100))])
409+
import plotly.plotly as py
410+
from plotly.graph_objs import Data, Scatter, Stream
411+
stream_id = "your_stream_id" # See {plotly_domain}/settings
412+
py.plot(Data([Scatter(x=[], y=[],
413+
stream=Stream(token=stream_id, maxpoints=100))]))
413414
# Stream data to the import trace
414-
>>> stream = Stream(stream_id) # Initialize a stream object
415-
>>> stream.open() # Open the stream
416-
>>> stream.write(dict(x=1, y=1)) # Plot (1, 1) in your graph
415+
stream = Stream(stream_id) # Initialize a stream object
416+
stream.open() # Open the stream
417+
stream.write(dict(x=1, y=1)) # Plot (1, 1) in your graph
417418
"""
418419

419420
@utils.template_doc(**tools.get_config_file())
@@ -536,7 +537,7 @@ def write(self, trace, layout=None, validate=True,
536537
stream_object.update(dict(layout=layout))
537538

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

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

603604
url = get_config()['plotly_domain'] + "/apigenimage/"
604605
res = requests.post(
605-
url, data=json.dumps(payload, cls=utils._plotlyJSONEncoder),
606+
url, data=json.dumps(payload, cls=utils.PlotlyJSONEncoder),
606607
headers=headers, verify=get_config()['plotly_ssl_verification']
607608
)
608609

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

825826
payload = {
826827
'filename': filename,
827-
'data': json.dumps(grid_json, cls=utils._plotlyJSONEncoder),
828+
'data': json.dumps(grid_json, cls=utils.PlotlyJSONEncoder),
828829
'world_readable': world_readable
829830
}
830831

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

907908
payload = {
908-
'cols': json.dumps(columns, cls=utils._plotlyJSONEncoder)
909+
'cols': json.dumps(columns, cls=utils.PlotlyJSONEncoder)
909910
}
910911

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

982983
payload = {
983-
'rows': json.dumps(rows, cls=utils._plotlyJSONEncoder)
984+
'rows': json.dumps(rows, cls=utils.PlotlyJSONEncoder)
984985
}
985986

986987
api_url = (_api_v2.api_url('grids')+
@@ -1098,7 +1099,7 @@ def upload(cls, meta, grid=None, grid_url=None):
10981099
grid_id = _api_v2.parse_grid_id_args(grid, grid_url)
10991100

11001101
payload = {
1101-
'metadata': json.dumps(meta, cls=utils._plotlyJSONEncoder)
1102+
'metadata': json.dumps(meta, cls=utils.PlotlyJSONEncoder)
11021103
}
11031104

11041105
api_url = _api_v2.api_url('grids')+'/{grid_id}'.format(grid_id=grid_id)
@@ -1206,14 +1207,14 @@ def _send_to_plotly(figure, **plot_options):
12061207
"""
12071208
fig = tools._replace_newline(figure) # does not mutate figure
12081209
data = json.dumps(fig['data'] if 'data' in fig else [],
1209-
cls=utils._plotlyJSONEncoder)
1210+
cls=utils.PlotlyJSONEncoder)
12101211
username, api_key = _get_session_username_and_key()
12111212
kwargs = json.dumps(dict(filename=plot_options['filename'],
12121213
fileopt=plot_options['fileopt'],
12131214
world_readable=plot_options['world_readable'],
12141215
layout=fig['layout'] if 'layout' in fig
12151216
else {}),
1216-
cls=utils._plotlyJSONEncoder)
1217+
cls=utils.PlotlyJSONEncoder)
12171218

12181219

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

plotly/tests/test_core/test_get_figure/test_get_figure.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
from plotly.plotly import plotly as py
1010
from plotly import exceptions
1111
from nose.tools import raises
12+
import six
13+
import json
14+
15+
from unittest import TestCase
16+
from unittest import skipIf
1217

1318

1419
# username for tests: 'plotlyimagetest'
@@ -191,4 +196,14 @@ def test_all():
191196
"following output is produced...")
192197

193198

199+
class TestBytesVStrings(TestCase):
194200

201+
@skipIf(not six.PY3, 'Decoding and missing escapes is only seen in PY3')
202+
def test_proper_escaping(self):
203+
un = 'PlotlyImageTest'
204+
ak = '786r5mecv0'
205+
url = "https://plot.ly/~PlotlyImageTest/91/"
206+
py.sign_in(un, ak)
207+
print("getting: https://plot.ly/~PlotlyImageTest/91/")
208+
print("###########################################\n\n")
209+
fig = py.get_figure(url)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def setup_package():
2+
import warnings
3+
warnings.filterwarnings('ignore')

0 commit comments

Comments
 (0)