Skip to content

Commit a8a0c9b

Browse files
Merge pull request #3817 from wf-r/selector_0_fix
FIX selector = 0 returns all traces in select_traces
2 parents 5cc3c81 + fb7bd75 commit a8a0c9b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Diff for: packages/python/plotly/plotly/basedatatypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ def select_traces(self, selector=None, row=None, col=None, secondary_y=None):
11391139
Generator that iterates through all of the traces that satisfy
11401140
all of the specified selection criteria
11411141
"""
1142-
if not selector:
1142+
if not selector and not isinstance(selector, int):
11431143
selector = {}
11441144

11451145
if row is not None or col is not None or secondary_y is not None:

Diff for: packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_traces.py

+4
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ def select_traces_fixture():
430430

431431
def test_select_traces_integer(select_traces_fixture):
432432
fig = select_traces_fixture
433+
# check that selecting first trace does indeed only select the first
434+
tr = list(fig.select_traces(selector=0))
435+
assert len(tr) == 1
436+
assert tr[0].y[1] == 0
433437
# check we can index last trace selected
434438
tr = list(fig.select_traces(selector=-1))[0]
435439
assert tr.y[1] == 20

0 commit comments

Comments
 (0)