|
10 | 10 | from copy import deepcopy, copy
|
11 | 11 |
|
12 | 12 | from _plotly_utils.utils import _natural_sort_strings
|
13 |
| -from plotly._validate import validate |
14 | 13 | from .optional_imports import get_module
|
15 | 14 |
|
16 | 15 | # Create Undefined sentinel value
|
@@ -92,6 +91,9 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
|
92 | 91 |
|
93 | 92 | super(BaseFigure, self).__init__()
|
94 | 93 |
|
| 94 | + # Initialize validation |
| 95 | + self._validate = kwargs.pop("validate", True) |
| 96 | + |
95 | 97 | # Assign layout_plotly to layout
|
96 | 98 | # ------------------------------
|
97 | 99 | # See docstring note for explanation
|
@@ -140,7 +142,9 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
|
140 | 142 | self._data_validator = DataValidator(set_uid=self._set_trace_uid)
|
141 | 143 |
|
142 | 144 | # ### Import traces ###
|
143 |
| - data = self._data_validator.validate_coerce(data, skip_invalid=skip_invalid) |
| 145 | + data = self._data_validator.validate_coerce( |
| 146 | + data, skip_invalid=skip_invalid, validate=self._validate |
| 147 | + ) |
144 | 148 |
|
145 | 149 | # ### Save tuple of trace objects ###
|
146 | 150 | self._data_objs = data
|
@@ -182,7 +186,7 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
|
182 | 186 |
|
183 | 187 | # ### Import Layout ###
|
184 | 188 | self._layout_obj = self._layout_validator.validate_coerce(
|
185 |
| - layout, skip_invalid=skip_invalid |
| 189 | + layout, skip_invalid=skip_invalid, validate=self._validate |
186 | 190 | )
|
187 | 191 |
|
188 | 192 | # ### Import clone of layout properties ###
|
@@ -314,6 +318,8 @@ def __setitem__(self, prop, value):
|
314 | 318 | for p in prop[:-1]:
|
315 | 319 | res = res[p]
|
316 | 320 |
|
| 321 | + res._validate = self._validate |
| 322 | + |
317 | 323 | res[prop[-1]] = value
|
318 | 324 |
|
319 | 325 | def __setattr__(self, prop, value):
|
@@ -1940,10 +1946,14 @@ def _initialize_layout_template(self):
|
1940 | 1946 |
|
1941 | 1947 | if self._layout_obj._props.get("template", None) is None:
|
1942 | 1948 | if pio.templates.default is not None:
|
1943 |
| - with validate(False): |
1944 |
| - # Assume default template is already validated |
| 1949 | + # Assume default template is already validated |
| 1950 | + self._layout_obj._validate = False |
| 1951 | + try: |
1945 | 1952 | template_dict = pio.templates[pio.templates.default]
|
1946 | 1953 | self._layout_obj.template = template_dict
|
| 1954 | + except Exception: |
| 1955 | + self._layout_obj._validate = self._validate |
| 1956 | + raise |
1947 | 1957 |
|
1948 | 1958 | @property
|
1949 | 1959 | def layout(self):
|
@@ -3339,6 +3349,8 @@ def __init__(self, plotly_name, **kwargs):
|
3339 | 3349 | # invalid properties will result in an exception
|
3340 | 3350 | self._skip_invalid = False
|
3341 | 3351 |
|
| 3352 | + self._validate = True |
| 3353 | + |
3342 | 3354 | # Validate inputs
|
3343 | 3355 | # ---------------
|
3344 | 3356 | self._process_kwargs(**kwargs)
|
@@ -3378,6 +3390,14 @@ def __init__(self, plotly_name, **kwargs):
|
3378 | 3390 | # ### Backing property for backward compatible _validator property ##
|
3379 | 3391 | self.__validators = None
|
3380 | 3392 |
|
| 3393 | + # @property |
| 3394 | + # def _validate(self): |
| 3395 | + # fig = self.figure |
| 3396 | + # if fig is None: |
| 3397 | + # return True |
| 3398 | + # else: |
| 3399 | + # return fig._validate |
| 3400 | + |
3381 | 3401 | def _get_validator(self, prop):
|
3382 | 3402 | from .validator_cache import ValidatorCache
|
3383 | 3403 |
|
@@ -3425,7 +3445,7 @@ def _process_kwargs(self, **kwargs):
|
3425 | 3445 | if k in self:
|
3426 | 3446 | # e.g. underscore kwargs like marker_line_color
|
3427 | 3447 | self[k] = v
|
3428 |
| - elif not validate._should_validate: |
| 3448 | + elif not self._validate: |
3429 | 3449 | # Set extra property as-is
|
3430 | 3450 | self[k] = v
|
3431 | 3451 | else:
|
@@ -3885,7 +3905,7 @@ def __setitem__(self, prop, value):
|
3885 | 3905 | # ### Unwrap scalar tuple ###
|
3886 | 3906 | prop = prop[0]
|
3887 | 3907 |
|
3888 |
| - if validate._should_validate: |
| 3908 | + if self._validate: |
3889 | 3909 | if prop not in self._valid_props:
|
3890 | 3910 | self._raise_on_invalid_property_error(prop)
|
3891 | 3911 |
|
@@ -3937,6 +3957,8 @@ def __setitem__(self, prop, value):
|
3937 | 3957 | for p in prop[:-1]:
|
3938 | 3958 | res = res[p]
|
3939 | 3959 |
|
| 3960 | + res._validate = self._validate |
| 3961 | + |
3940 | 3962 | res[prop[-1]] = value
|
3941 | 3963 |
|
3942 | 3964 | def __setattr__(self, prop, value):
|
|
0 commit comments