-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
♻️ 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
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eff3a3e
:recycle: avoid deepcopy of dict in validate_coerce
jvdd 24c82c5
:dash: avoid deepcopy in validate_coerce when BaseTraceType
jonasvdd 3c5d8e8
Merge branch 'master' into avoid_deepcopy
jvdd 374d59f
:pen: check for histogram2dcontour
jvdd 68d7180
:broom: formatting
jvdd 3dc764e
Update packages/python/plotly/_plotly_utils/basevalidators.py
alexcjohnson 605ac4f
Update packages/python/plotly/_plotly_utils/basevalidators.py
alexcjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: | ||
|
|
@@ -2641,34 +2636,31 @@ 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 | ||
jvdd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.