Skip to content

Commit ba52ba3

Browse files
committed
Merge pull request plotly#131 from plotly/andrew-better-empty-data-error
Andrew better empty data error
2 parents 835d5a4 + 0deae65 commit ba52ba3

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

plotly/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ class PlotlyError(Exception):
2323
pass
2424

2525

26+
## Would Cause Server Errors ##
27+
28+
class PlotlyEmptyDataError(PlotlyError):
29+
pass
30+
31+
2632
## Graph Objects Errors ##
2733

2834
class PlotlyGraphObjectError(PlotlyError):

plotly/plotly/plotly.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ def plot(figure_or_data, validate=True, **plot_options):
164164
"plot option.\nHere's why you're "
165165
"seeing this error:\n\n{0}"
166166
"".format(err))
167+
if not figure['data']:
168+
raise exceptions.PlotlyEmptyDataError(
169+
"Empty data list found. Make sure that you populated the "
170+
"list of data objects you're sending and try again.\n"
171+
"Questions? [email protected]"
172+
)
167173
for entry in figure['data']:
168174
for key, val in list(entry.items()):
169175
try:

plotly/tests/test_core/test_plotly/test_plot.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
"""
88
from __future__ import absolute_import
99
from nose.tools import raises
10+
from unittest import TestCase
1011

1112
from plotly.graph_objs import graph_objs
1213
from plotly.plotly import plotly as py
13-
from plotly.exceptions import PlotlyError
14+
from plotly.exceptions import PlotlyError, PlotlyEmptyDataError
1415

1516

1617
# username for tests: 'PlotlyImageTest'
@@ -57,6 +58,14 @@ def test_plot_invalid_args_2():
5758
filename='plot_invalid')
5859

5960

61+
class TestPlot(TestCase):
62+
63+
def test_plot_empty_data(self):
64+
py.sign_in('PlotlyImageTest', '786r5mecv0')
65+
with self.assertRaises(PlotlyEmptyDataError):
66+
py.plot([], filename='plot_invalid')
67+
68+
6069
def test_bar():
6170
pass
6271

0 commit comments

Comments
 (0)