Skip to content

Commit a2b0ca0

Browse files
committed
rest of chris' comments
1 parent dfd1b2c commit a2b0ca0

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

plotly/figure_factory/_bullet.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import
22

3+
import collections
34
import math
45

56
from plotly import colors, exceptions, optional_imports
@@ -11,6 +12,11 @@
1112
pd = optional_imports.get_module('pandas')
1213

1314

15+
def is_sequence(obj):
16+
return (isinstance(obj, collections.Sequence) and
17+
not isinstance(obj, basestring))
18+
19+
1420
def _bullet(df, markers, measures, ranges, subtitles, titles, orientation,
1521
range_colors, measure_colors, horizontal_spacing,
1622
vertical_spacing, scatter_options, layout_options):
@@ -255,11 +261,11 @@ def create_bullet(data, markers=None, measures=None, ranges=None,
255261
"'pandas' must be installed for this figure factory."
256262
)
257263

258-
if isinstance(data, (tuple, list)):
264+
if is_sequence(data):
259265
if not all(isinstance(item, dict) for item in data):
260266
raise exceptions.PlotlyError(
261-
'Every entry of the data argument (a list or tuple) must be '
262-
'a dictionary.'
267+
'Every entry of the data argument (list, tuple, etc) must '
268+
'be a dictionary.'
263269
)
264270

265271
elif not isinstance(data, pd.DataFrame):
@@ -270,7 +276,7 @@ def create_bullet(data, markers=None, measures=None, ranges=None,
270276

271277
# make DataFrame from data with correct column headers
272278
col_names = ['titles', 'subtitle', 'markers', 'measures', 'ranges']
273-
if isinstance(data, (tuple, list)):
279+
if is_sequence(data):
274280
df = pd.DataFrame(
275281
[
276282
[d[titles] for d in data] if titles else [''] * len(data),

plotly/tests/test_optional/test_figure_factory.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,10 @@ def test_df_as_list(self):
21932193
'foo'
21942194
]
21952195

2196-
pattern = ('If your data is a list, all entries must be dictionaries.')
2196+
pattern = (
2197+
'Every entry of the data argument (list, tuple, etc) must '
2198+
'be a dictionary.'
2199+
)
21972200
self.assertRaisesRegexp(PlotlyError, pattern, ff.create_bullet, df)
21982201

21992202
def test_not_df_or_list(self):

0 commit comments

Comments
 (0)