From eff3a3e5764863d813771ddce2635ef9f73ff647 Mon Sep 17 00:00:00 2001 From: Jeroen Van Der Donckt Date: Thu, 3 Nov 2022 09:52:48 +0100 Subject: [PATCH 1/6] :recycle: avoid deepcopy of dict in validate_coerce --- .../plotly/_plotly_utils/basevalidators.py | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/python/plotly/_plotly_utils/basevalidators.py b/packages/python/plotly/_plotly_utils/basevalidators.py index f68bc63f761..4845a9bc2d9 100644 --- a/packages/python/plotly/_plotly_utils/basevalidators.py +++ b/packages/python/plotly/_plotly_utils/basevalidators.py @@ -7,7 +7,6 @@ from importlib import import_module import copy import io -from copy import deepcopy import re import sys @@ -2626,10 +2625,6 @@ def get_trace_class(self, trace_name): def validate_coerce(self, v, skip_invalid=False, _validate=True): from plotly.basedatatypes import BaseTraceType - # Import Histogram2dcontour, this is the deprecated name of the - # Histogram2dContour trace. - from plotly.graph_objs import Histogram2dcontour - if v is None: v = [] else: @@ -2645,20 +2640,14 @@ def validate_coerce(self, v, skip_invalid=False, _validate=True): v_el = v_el.to_plotly_json() if isinstance(v_el, dict): - v_copy = deepcopy(v_el) - - if "type" in v_copy: - trace_type = v_copy.pop("type") - elif isinstance(v_el, Histogram2dcontour): - trace_type = "histogram2dcontour" - else: - trace_type = "scatter" + type_in_v_el = "type" in v_el + trace_type = v_el.pop("type", "scatter") if trace_type not in self.class_strs_map: if skip_invalid: # Treat as scatter trace trace = self.get_trace_class("scatter")( - skip_invalid=skip_invalid, _validate=_validate, **v_copy + skip_invalid=skip_invalid, _validate=_validate, **v_el ) res.append(trace) else: @@ -2666,9 +2655,13 @@ def validate_coerce(self, v, skip_invalid=False, _validate=True): invalid_els.append(v_el) else: trace = self.get_trace_class(trace_type)( - skip_invalid=skip_invalid, _validate=_validate, **v_copy + skip_invalid=skip_invalid, _validate=_validate, **v_el ) res.append(trace) + + if type_in_v_el: + # Restore type in v_el + v_el["type"] = trace_type else: if skip_invalid: # Add empty scatter trace From 24c82c51f9f6d772e15fd65e4bf4b495720eeab4 Mon Sep 17 00:00:00 2001 From: jonasvdd Date: Thu, 3 Nov 2022 10:48:18 +0100 Subject: [PATCH 2/6] :dash: avoid deepcopy in validate_coerce when BaseTraceType --- packages/python/plotly/_plotly_utils/basevalidators.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/python/plotly/_plotly_utils/basevalidators.py b/packages/python/plotly/_plotly_utils/basevalidators.py index 4845a9bc2d9..59edebfd4ac 100644 --- a/packages/python/plotly/_plotly_utils/basevalidators.py +++ b/packages/python/plotly/_plotly_utils/basevalidators.py @@ -2636,8 +2636,7 @@ def validate_coerce(self, v, skip_invalid=False, _validate=True): for v_el in v: if isinstance(v_el, BaseTraceType): - # Clone input traces - v_el = v_el.to_plotly_json() + v_el = v_el._props if isinstance(v_el, dict): type_in_v_el = "type" in v_el From 374d59f51d19e499db534572af96008a8518b31d Mon Sep 17 00:00:00 2001 From: Jeroen Van Der Donckt <18898740+jvdd@users.noreply.github.com> Date: Wed, 7 Jun 2023 12:01:56 +0200 Subject: [PATCH 3/6] :pen: check for histogram2dcontour Co-authored-by: Alex Johnson --- packages/python/plotly/_plotly_utils/basevalidators.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/python/plotly/_plotly_utils/basevalidators.py b/packages/python/plotly/_plotly_utils/basevalidators.py index ca7699b0c8c..711fc2ed3aa 100644 --- a/packages/python/plotly/_plotly_utils/basevalidators.py +++ b/packages/python/plotly/_plotly_utils/basevalidators.py @@ -2657,7 +2657,11 @@ def validate_coerce(self, v, skip_invalid=False, _validate=True): for v_el in v: if isinstance(v_el, BaseTraceType): - v_el = v_el._props + if isinstance(v_el, Histogram2dcontour): + v_el = dict(type="histogram2dcontour", **v_el._props) + else: + v_el = v_el._props + if isinstance(v_el, dict): type_in_v_el = "type" in v_el From 68d71804fed0e36777b4e6cf14c04616eac39a2a Mon Sep 17 00:00:00 2001 From: Jeroen Van Der Donckt Date: Wed, 7 Jun 2023 12:22:19 +0200 Subject: [PATCH 4/6] :broom: formatting --- packages/python/plotly/_plotly_utils/basevalidators.py | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/python/plotly/_plotly_utils/basevalidators.py b/packages/python/plotly/_plotly_utils/basevalidators.py index 711fc2ed3aa..e44ae730335 100644 --- a/packages/python/plotly/_plotly_utils/basevalidators.py +++ b/packages/python/plotly/_plotly_utils/basevalidators.py @@ -2661,7 +2661,6 @@ def validate_coerce(self, v, skip_invalid=False, _validate=True): v_el = dict(type="histogram2dcontour", **v_el._props) else: v_el = v_el._props - if isinstance(v_el, dict): type_in_v_el = "type" in v_el From 3dc764e67d78cd2dcd2a17b323afe26e5560ed04 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Wed, 7 Jun 2023 16:47:26 -0400 Subject: [PATCH 5/6] Update packages/python/plotly/_plotly_utils/basevalidators.py --- packages/python/plotly/_plotly_utils/basevalidators.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/python/plotly/_plotly_utils/basevalidators.py b/packages/python/plotly/_plotly_utils/basevalidators.py index e44ae730335..e4db680d68d 100644 --- a/packages/python/plotly/_plotly_utils/basevalidators.py +++ b/packages/python/plotly/_plotly_utils/basevalidators.py @@ -2646,6 +2646,9 @@ def get_trace_class(self, trace_name): def validate_coerce(self, v, skip_invalid=False, _validate=True): from plotly.basedatatypes import BaseTraceType + # Import Histogram2dcontour, this is the deprecated name of the + # Histogram2dContour trace. + from plotly.graph_objs import Histogram2dcontour if v is None: v = [] else: From 605ac4fc717b79ec679866a2106728ac3d07ac01 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Wed, 7 Jun 2023 16:48:13 -0400 Subject: [PATCH 6/6] Update packages/python/plotly/_plotly_utils/basevalidators.py --- packages/python/plotly/_plotly_utils/basevalidators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/python/plotly/_plotly_utils/basevalidators.py b/packages/python/plotly/_plotly_utils/basevalidators.py index e4db680d68d..e0c93699e72 100644 --- a/packages/python/plotly/_plotly_utils/basevalidators.py +++ b/packages/python/plotly/_plotly_utils/basevalidators.py @@ -2649,6 +2649,7 @@ def validate_coerce(self, v, skip_invalid=False, _validate=True): # Import Histogram2dcontour, this is the deprecated name of the # Histogram2dContour trace. from plotly.graph_objs import Histogram2dcontour + if v is None: v = [] else: