Skip to content

Commit 8ca6ee3

Browse files
nicholas-esterernicolaskruchten
authored andcommitted
Cast the returned iterators to generators
1 parent 4d19994 commit 8ca6ee3

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

packages/python/plotly/plotly/basedatatypes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,12 @@ def _axis_spanning_shapes_docstr(shape_type):
382382
return docstr
383383

384384

385+
def _generator(i):
386+
""" "cast" an iterator to a generator """
387+
while True:
388+
yield next(i)
389+
390+
385391
class BaseFigure(object):
386392
"""
387393
Base class for all figure types (both widget and non-widget)
@@ -1186,7 +1192,7 @@ def _filter_by_subplot_ref(trace):
11861192
if filter_by_subplot:
11871193
funcs.append(_filter_by_subplot_ref)
11881194

1189-
return self._filter_by_selector(self.data, funcs, selector)
1195+
return _generator(self._filter_by_selector(self.data, funcs, selector))
11901196

11911197
@staticmethod
11921198
def _selector_matches(obj, selector):
@@ -1439,7 +1445,7 @@ def _select_layout_subplots_by_prefix(
14391445
_natural_sort_strings(list(self.layout)),
14401446
)
14411447
layout_objs = [self.layout[k] for k in layout_keys]
1442-
return self._filter_by_selector(layout_objs, [], selector)
1448+
return _generator(self._filter_by_selector(layout_objs, [], selector))
14431449

14441450
def _select_annotations_like(
14451451
self, prop, selector=None, row=None, col=None, secondary_y=None
@@ -1486,7 +1492,7 @@ def _filter_sec_y(obj):
14861492

14871493
funcs = [_filter_row, _filter_col, _filter_sec_y]
14881494

1489-
return self._filter_by_selector(self.layout[prop], funcs, selector)
1495+
return _generator(self._filter_by_selector(self.layout[prop], funcs, selector))
14901496

14911497
def _add_annotation_like(
14921498
self,

packages/python/plotly/plotly/tests/test_core/test_update_objects/test_selector_matches.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ def _sel(d):
8989
return d["x"] == 1 and d["y"] == 3 and d["text"] == "pat metheny"
9090

9191
assert BaseFigure._selector_matches(obj, _sel) == False
92+
93+
94+
def test_string_selector_matches_type_key():
95+
assert BaseFigure._selector_matches(dict(type="bar"), "bar")
96+
assert BaseFigure._selector_matches(dict(type="scatter"), "bar") == False

packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_traces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def f(t):
260260

261261
def test_select_traces_type_error(self):
262262
with self.assertRaises(TypeError):
263-
self.assert_select_traces([0], selector=123, row=1, col=1)
263+
self.assert_select_traces([0], selector=123.456, row=1, col=1)
264264

265265
def test_for_each_trace_lowercase_names(self):
266266
# Names are all uppercase to start

0 commit comments

Comments
 (0)