Skip to content

Commit e197f57

Browse files
authoredSep 25, 2018
Add deepcopy and pickle support to figures and graph objects (#1191)
* Allow kwargs to override properties in codegen validator subclasses This will make it easier to implement generic validator deepcopy support * Make all validators support deepcopy * Avoid infinite loops when checking for existence of _subplotid_props in Layout * Add __reduce__ methods to BaseFigure and BasePlotlyType This method provides pickle and deep copy support * Add tests for deepcopy and pickle support
1 parent fac00f1 commit e197f57

File tree

5,565 files changed

+18859
-16791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,565 files changed

+18859
-16791
lines changed
 

Diff for: ‎_plotly_utils/basevalidators.py

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import textwrap
44
import uuid
55
from importlib import import_module
6+
import copy
67

78
import io
89
from copy import deepcopy
@@ -373,6 +374,7 @@ def __init__(self,
373374
self.array_ok = array_ok
374375
# coerce_number is rarely used and not implemented
375376
self.coerce_number = coerce_number
377+
self.kwargs = kwargs
376378

377379
# Handle regular expressions
378380
# --------------------------
@@ -398,6 +400,17 @@ def __init__(self,
398400
self.val_regexs.append(None)
399401
self.regex_replacements.append(None)
400402

403+
def __deepcopy__(self, memodict={}):
404+
"""
405+
A custom deepcopy method is needed here because compiled regex
406+
objects don't support deepcopy
407+
"""
408+
cls = self.__class__
409+
return cls(
410+
self.plotly_name,
411+
self.parent_name,
412+
values=self.values)
413+
401414
@staticmethod
402415
def build_regex_replacement(regex_str):
403416
# Example: regex_str == r"^y([2-9]|[1-9][0-9]+)?$"

Diff for: ‎codegen/validators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(self, plotly_name={params['plotly_name']},
6363
continue
6464

6565
buffer.write(f""",
66-
{attr_name}={attr_val}""")
66+
{attr_name}=kwargs.pop('{attr_name}', {attr_val})""")
6767

6868
buffer.write(f""",
6969
**kwargs""")

0 commit comments

Comments
 (0)
Please sign in to comment.