Skip to content

Commit

Permalink
Merge pull request #3946 from jvdd/avoid_deepcopy
Browse files Browse the repository at this point in the history
♻️ avoid deepcopy of dict in validate_coerce
  • Loading branch information
alexcjohnson authored Jun 7, 2023
2 parents 216fca2 + 605ac4f commit d1668b6
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/python/plotly/_plotly_utils/basevalidators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from importlib import import_module
import copy
import io
from copy import deepcopy
import re
import sys

Expand Down Expand Up @@ -2662,34 +2661,34 @@ 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()
if isinstance(v_el, Histogram2dcontour):
v_el = dict(type="histogram2dcontour", **v_el._props)
else:
v_el = v_el._props

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:
res.append(None)
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
Expand Down

0 comments on commit d1668b6

Please sign in to comment.