Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 06915b3

Browse files
committedDec 21, 2023
adjust validators
1 parent 954a90e commit 06915b3

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed
 

‎packages/python/plotly/_plotly_utils/basevalidators.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ def is_typed_array_spec(v):
291291
return isinstance(v, dict) and "bdata" in v
292292

293293

294+
def is_none_or_typed_array_spec(v):
295+
return v is None or is_typed_array_spec(v)
296+
297+
294298
def is_simple_array(v):
295299
"""
296300
Return whether a value is considered to be an simple array
@@ -485,11 +489,7 @@ def description(self):
485489

486490
def validate_coerce(self, v):
487491

488-
if v is None:
489-
# Pass None through
490-
pass
491-
elif is_typed_array_spec(v):
492-
# Pass typed array spec through
492+
if is_none_or_typed_array_spec(v):
493493
pass
494494
elif is_homogeneous_array(v):
495495
v = to_typed_array_spec(v)
@@ -686,8 +686,7 @@ def in_values(self, e):
686686
return False
687687

688688
def validate_coerce(self, v):
689-
if v is None:
690-
# Pass None through
689+
if is_none_or_typed_array_spec(v):
691690
pass
692691
elif self.array_ok and is_array(v):
693692
v_replaced = [self.perform_replacemenet(v_el) for v_el in v]
@@ -847,8 +846,7 @@ def description(self):
847846
return desc
848847

849848
def validate_coerce(self, v):
850-
if v is None:
851-
# Pass None through
849+
if is_none_or_typed_array_spec(v):
852850
pass
853851
elif self.array_ok and is_homogeneous_array(v):
854852
np = get_module("numpy")
@@ -975,8 +973,7 @@ def description(self):
975973
return desc
976974

977975
def validate_coerce(self, v):
978-
if v is None:
979-
# Pass None through
976+
if is_none_or_typed_array_spec(v):
980977
pass
981978
elif self.array_ok and is_homogeneous_array(v):
982979
np = get_module("numpy")
@@ -1130,8 +1127,7 @@ def description(self):
11301127
return desc
11311128

11321129
def validate_coerce(self, v):
1133-
if v is None:
1134-
# Pass None through
1130+
if is_none_or_typed_array_spec(v):
11351131
pass
11361132
elif self.array_ok and is_array(v):
11371133

@@ -1432,8 +1428,7 @@ def description(self):
14321428
return valid_color_description
14331429

14341430
def validate_coerce(self, v, should_raise=True):
1435-
if v is None:
1436-
# Pass None through
1431+
if is_none_or_typed_array_spec(v):
14371432
pass
14381433
elif self.array_ok and is_homogeneous_array(v):
14391434
v = copy_to_readonly_numpy_array(v)
@@ -1577,8 +1572,7 @@ def description(self):
15771572

15781573
def validate_coerce(self, v):
15791574

1580-
if v is None:
1581-
# Pass None through
1575+
if is_none_or_typed_array_spec(v):
15821576
pass
15831577
elif is_array(v):
15841578
validated_v = [
@@ -1783,8 +1777,7 @@ def description(self):
17831777
return desc
17841778

17851779
def validate_coerce(self, v):
1786-
if v is None:
1787-
# Pass None through
1780+
if is_none_or_typed_array_spec(v):
17881781
pass
17891782
elif self.array_ok and is_homogeneous_array(v):
17901783
try:
@@ -1972,6 +1965,9 @@ def validate_coerce(self, v):
19721965
if v is None:
19731966
# Pass None through
19741967
pass
1968+
if is_typed_array_spec(v):
1969+
# Pass typed array spec through
1970+
pass
19751971
elif self.array_ok and is_array(v):
19761972

19771973
# Coerce individual strings
@@ -2028,8 +2024,7 @@ def description(self):
20282024
return desc
20292025

20302026
def validate_coerce(self, v):
2031-
if v is None:
2032-
# Pass None through
2027+
if is_none_or_typed_array_spec(v):
20332028
pass
20342029
elif self.array_ok and is_homogeneous_array(v):
20352030
v = copy_to_readonly_numpy_array(v, kind="O")
@@ -2237,8 +2232,7 @@ def validate_element_with_indexed_name(self, val, validator, inds):
22372232
return val
22382233

22392234
def validate_coerce(self, v):
2240-
if v is None:
2241-
# Pass None through
2235+
if is_none_or_typed_array_spec(v):
22422236
return None
22432237
elif not is_array(v):
22442238
self.raise_invalid_val(v)
@@ -2301,7 +2295,7 @@ def validate_coerce(self, v):
23012295
return v
23022296

23032297
def present(self, v):
2304-
if v is None:
2298+
if is_none_or_typed_array_spec(v):
23052299
return None
23062300
else:
23072301
if (

0 commit comments

Comments
 (0)
Please sign in to comment.