@@ -223,6 +223,17 @@ def type_str(v):
223
223
return "'{module}.{name}'" .format (module = v .__module__ , name = v .__name__ )
224
224
225
225
226
+ def is_typed_array_spec (v ):
227
+ """
228
+ Return whether a value is considered to be a typed array spec for plotly.js
229
+ """
230
+ return isinstance (v , dict ) and "bdata" in v and "dtype" in v
231
+
232
+
233
+ def is_none_or_typed_array_spec (v ):
234
+ return v is None or is_typed_array_spec (v )
235
+
236
+
226
237
# Validators
227
238
# ----------
228
239
class BaseValidator (object ):
@@ -393,8 +404,7 @@ def description(self):
393
404
394
405
def validate_coerce (self , v ):
395
406
396
- if v is None :
397
- # Pass None through
407
+ if is_none_or_typed_array_spec (v ):
398
408
pass
399
409
elif is_homogeneous_array (v ):
400
410
v = copy_to_readonly_numpy_array (v )
@@ -591,8 +601,7 @@ def in_values(self, e):
591
601
return False
592
602
593
603
def validate_coerce (self , v ):
594
- if v is None :
595
- # Pass None through
604
+ if is_none_or_typed_array_spec (v ):
596
605
pass
597
606
elif self .array_ok and is_array (v ):
598
607
v_replaced = [self .perform_replacemenet (v_el ) for v_el in v ]
@@ -636,8 +645,7 @@ def description(self):
636
645
)
637
646
638
647
def validate_coerce (self , v ):
639
- if v is None :
640
- # Pass None through
648
+ if is_none_or_typed_array_spec (v ):
641
649
pass
642
650
elif not isinstance (v , bool ):
643
651
self .raise_invalid_val (v )
@@ -661,8 +669,7 @@ def description(self):
661
669
)
662
670
663
671
def validate_coerce (self , v ):
664
- if v is None :
665
- # Pass None through
672
+ if is_none_or_typed_array_spec (v ):
666
673
pass
667
674
elif isinstance (v , str ):
668
675
pass
@@ -752,8 +759,7 @@ def description(self):
752
759
return desc
753
760
754
761
def validate_coerce (self , v ):
755
- if v is None :
756
- # Pass None through
762
+ if is_none_or_typed_array_spec (v ):
757
763
pass
758
764
elif self .array_ok and is_homogeneous_array (v ):
759
765
np = get_module ("numpy" )
@@ -899,8 +905,7 @@ def description(self):
899
905
return desc
900
906
901
907
def validate_coerce (self , v ):
902
- if v is None :
903
- # Pass None through
908
+ if is_none_or_typed_array_spec (v ):
904
909
pass
905
910
elif v in self .extras :
906
911
return v
@@ -1063,8 +1068,7 @@ def description(self):
1063
1068
return desc
1064
1069
1065
1070
def validate_coerce (self , v ):
1066
- if v is None :
1067
- # Pass None through
1071
+ if is_none_or_typed_array_spec (v ):
1068
1072
pass
1069
1073
elif self .array_ok and is_array (v ):
1070
1074
@@ -1365,8 +1369,7 @@ def description(self):
1365
1369
return valid_color_description
1366
1370
1367
1371
def validate_coerce (self , v , should_raise = True ):
1368
- if v is None :
1369
- # Pass None through
1372
+ if is_none_or_typed_array_spec (v ):
1370
1373
pass
1371
1374
elif self .array_ok and is_homogeneous_array (v ):
1372
1375
v = copy_to_readonly_numpy_array (v )
@@ -1510,8 +1513,7 @@ def description(self):
1510
1513
1511
1514
def validate_coerce (self , v ):
1512
1515
1513
- if v is None :
1514
- # Pass None through
1516
+ if is_none_or_typed_array_spec (v ):
1515
1517
pass
1516
1518
elif is_array (v ):
1517
1519
validated_v = [
@@ -1708,16 +1710,17 @@ def description(self):
1708
1710
(e.g. 270 is converted to -90).
1709
1711
""" .format (
1710
1712
plotly_name = self .plotly_name ,
1711
- array_ok = ", or a list, numpy array or other iterable thereof"
1712
- if self .array_ok
1713
- else "" ,
1713
+ array_ok = (
1714
+ ", or a list, numpy array or other iterable thereof"
1715
+ if self .array_ok
1716
+ else ""
1717
+ ),
1714
1718
)
1715
1719
1716
1720
return desc
1717
1721
1718
1722
def validate_coerce (self , v ):
1719
- if v is None :
1720
- # Pass None through
1723
+ if is_none_or_typed_array_spec (v ):
1721
1724
pass
1722
1725
elif self .array_ok and is_homogeneous_array (v ):
1723
1726
try :
@@ -1902,8 +1905,7 @@ def vc_scalar(self, v):
1902
1905
return None
1903
1906
1904
1907
def validate_coerce (self , v ):
1905
- if v is None :
1906
- # Pass None through
1908
+ if is_none_or_typed_array_spec (v ):
1907
1909
pass
1908
1910
elif self .array_ok and is_array (v ):
1909
1911
@@ -1961,8 +1963,7 @@ def description(self):
1961
1963
return desc
1962
1964
1963
1965
def validate_coerce (self , v ):
1964
- if v is None :
1965
- # Pass None through
1966
+ if is_none_or_typed_array_spec (v ):
1966
1967
pass
1967
1968
elif self .array_ok and is_homogeneous_array (v ):
1968
1969
v = copy_to_readonly_numpy_array (v , kind = "O" )
@@ -2170,8 +2171,7 @@ def validate_element_with_indexed_name(self, val, validator, inds):
2170
2171
return val
2171
2172
2172
2173
def validate_coerce (self , v ):
2173
- if v is None :
2174
- # Pass None through
2174
+ if is_none_or_typed_array_spec (v ):
2175
2175
return None
2176
2176
elif not is_array (v ):
2177
2177
self .raise_invalid_val (v )
0 commit comments