Skip to content

♻️ avoid deepcopy of dict in validate_coerce #3946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Contributor Author

@jvdd jvdd Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this check never hits as in in line 2647 is checked whether v_el is a dict.

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