Skip to content

Commit 23646ca

Browse files
committed
do not strip fig of invalid elements wen running .get_figure\nthis is consistent with favoring validation failure to user\nrelated to TODO #283 Issue\n new valid charts created from old PlotlyImageTest examples
1 parent b981e72 commit 23646ca

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

Diff for: plotly/plotly/plotly.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def get_figure(file_owner_or_url, file_id=None, raw=False):
474474

475475
if raw:
476476
return figure
477-
return tools.get_valid_graph_obj(figure, obj_type='Figure')
477+
return tools.get_graph_obj(figure, obj_type='Figure')
478478

479479

480480
@utils.template_doc(**tools.get_config_file())

Diff for: plotly/tests/test_core/test_get_figure/test_get_figure.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ class GetFigureTest(PlotlyTestCase):
4242
def test_get_figure(self):
4343
un = 'PlotlyImageTest'
4444
ak = '786r5mecv0'
45-
file_id = 2
45+
file_id = 13183
4646
py.sign_in(un, ak)
4747
py.get_figure('PlotlyImageTest', str(file_id))
4848

4949
@attr('slow')
5050
def test_get_figure_with_url(self):
5151
un = 'PlotlyImageTest'
5252
ak = '786r5mecv0'
53-
url = "https://plot.ly/~PlotlyImageTest/2/"
53+
url = "https://plot.ly/~PlotlyImageTest/13183/"
5454
py.sign_in(un, ak)
5555
py.get_figure(url)
5656

@@ -71,6 +71,15 @@ def test_get_figure_invalid_2(self):
7171
with self.assertRaises(exceptions.PlotlyError):
7272
py.get_figure(url)
7373

74+
# demonstrates error if fig has invalid parts
75+
def test_get_figure_invalid_3(self):
76+
un = 'PlotlyImageTest'
77+
ak = '786r5mecv0'
78+
url = "https://plot.ly/~PlotlyImageTest/2/"
79+
py.sign_in(un, ak)
80+
with self.assertRaises(ValueError):
81+
py.get_figure(url)
82+
7483
@attr('slow')
7584
def test_get_figure_does_not_exist(self):
7685
un = 'PlotlyImageTest'
@@ -95,6 +104,6 @@ class TestBytesVStrings(TestCase):
95104
def test_proper_escaping(self):
96105
un = 'PlotlyImageTest'
97106
ak = '786r5mecv0'
98-
url = "https://plot.ly/~PlotlyImageTest/91/"
107+
url = "https://plot.ly/~PlotlyImageTest/13185/"
99108
py.sign_in(un, ak)
100109
py.get_figure(url)

Diff for: plotly/tools.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1351,23 +1351,22 @@ def _pad(s, cell_len=cell_len):
13511351
return fig
13521352

13531353

1354-
def get_valid_graph_obj(obj, obj_type=None):
1355-
"""Returns a new graph object that won't raise.
1356-
1357-
CAREFUL: this will *silently* strip out invalid pieces of the object.
1354+
def get_graph_obj(obj, obj_type=None):
1355+
"""Returns a new graph object.
13581356
1357+
OLD FUNCTION: this will *silently* strip out invalid pieces of the object.
1358+
NEW FUNCTION: no striping of invalid pieces anymore - only raises error
1359+
on unrecognized graph_objs
13591360
"""
13601361
# TODO: Deprecate or move. #283
13611362
from plotly.graph_objs import graph_objs
13621363
try:
1363-
print(graph_objs)
1364-
print(obj_type)
13651364
cls = getattr(graph_objs, obj_type)
13661365
except (AttributeError, KeyError):
13671366
raise exceptions.PlotlyError(
13681367
"'{}' is not a recognized graph_obj.".format(obj_type)
13691368
)
1370-
return cls(obj, _raise=False)
1369+
return cls(obj)
13711370

13721371

13731372
def validate(obj, obj_type):

0 commit comments

Comments
 (0)