From 321c77230a794d9f0595038a2674c955889ed0e3 Mon Sep 17 00:00:00 2001 From: "Wolfgang F. Riedl" Date: Tue, 19 Jul 2022 07:45:15 +0200 Subject: [PATCH 1/4] Avoid selecting all traces on selector=0 --- packages/python/plotly/plotly/basedatatypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index 1a7cbb80073..c45c71f84f5 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: From 2e2054057a66d59f29c6e317bc34c822f63f5a4e Mon Sep 17 00:00:00 2001 From: "Wolfgang F. Riedl" Date: Tue, 19 Jul 2022 07:59:46 +0200 Subject: [PATCH 2/4] Update tests --- .../tests/test_core/test_update_objects/test_update_traces.py | 4 ++++ 1 file changed, 4 insertions(+) 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 0a47b6a6b4d..54c6a77bfc7 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 From 143ecfd072d8b30ae239c64ed82e6a70a9e1189e Mon Sep 17 00:00:00 2001 From: "Wolfgang F. Riedl" Date: Mon, 1 Aug 2022 11:13:31 +0200 Subject: [PATCH 3/4] Update test_update_traces.py --- .../tests/test_core/test_update_objects/test_update_traces.py | 1 + 1 file changed, 1 insertion(+) 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 54c6a77bfc7..7f08aa20db9 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,7 @@ 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 From fb7bd756309a0767911a3eb7ac8f0b81cd178dde Mon Sep 17 00:00:00 2001 From: "Wolfgang F. Riedl" Date: Mon, 1 Aug 2022 13:48:44 +0200 Subject: [PATCH 4/4] Update test_update_traces.py --- .../tests/test_core/test_update_objects/test_update_traces.py | 1 - 1 file changed, 1 deletion(-) 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 7f08aa20db9..54c6a77bfc7 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,7 +430,6 @@ 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