diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index 1a7cbb8007..c45c71f84f 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -1139,7 +1139,7 @@ def select_traces(self, selector=None, row=None, col=None, secondary_y=None): Generator that iterates through all of the traces that satisfy all of the specified selection criteria """ - if not selector: + if not selector and not isinstance(selector, int): selector = {} if row is not None or col is not None or secondary_y is not None: diff --git a/packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_traces.py b/packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_traces.py index 0a47b6a6b4..54c6a77bfc 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_traces.py +++ b/packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_traces.py @@ -430,6 +430,10 @@ def select_traces_fixture(): def test_select_traces_integer(select_traces_fixture): fig = select_traces_fixture + # check that selecting first trace does indeed only select the first + tr = list(fig.select_traces(selector=0)) + assert len(tr) == 1 + assert tr[0].y[1] == 0 # check we can index last trace selected tr = list(fig.select_traces(selector=-1))[0] assert tr.y[1] == 20