@@ -824,13 +824,21 @@ class IntegerValidator(BaseValidator):
824
824
"dflt",
825
825
"min",
826
826
"max",
827
+ "extras",
827
828
"arrayOk"
828
829
]
829
830
},
830
831
"""
831
832
832
833
def __init__ (
833
- self , plotly_name , parent_name , min = None , max = None , array_ok = False , ** kwargs
834
+ self ,
835
+ plotly_name ,
836
+ parent_name ,
837
+ min = None ,
838
+ max = None ,
839
+ extras = None ,
840
+ array_ok = False ,
841
+ ** kwargs ,
834
842
):
835
843
super (IntegerValidator , self ).__init__ (
836
844
plotly_name = plotly_name , parent_name = parent_name , ** kwargs
@@ -855,6 +863,7 @@ def __init__(
855
863
else :
856
864
self .has_min_max = False
857
865
866
+ self .extras = extras if extras is not None else []
858
867
self .array_ok = array_ok
859
868
860
869
def description (self ):
@@ -878,6 +887,16 @@ def description(self):
878
887
)
879
888
)
880
889
890
+ # Extras
891
+ if self .extras :
892
+ desc = (
893
+ desc
894
+ + (
895
+ """
896
+ OR exactly one of {extras} (e.g. '{eg_extra}')"""
897
+ ).format (extras = self .extras , eg_extra = self .extras [- 1 ])
898
+ )
899
+
881
900
if self .array_ok :
882
901
desc = (
883
902
desc
@@ -891,6 +910,8 @@ def validate_coerce(self, v):
891
910
if v is None :
892
911
# Pass None through
893
912
pass
913
+ elif v in self .extras :
914
+ return v
894
915
elif self .array_ok and is_homogeneous_array (v ):
895
916
np = get_module ("numpy" )
896
917
v_array = copy_to_readonly_numpy_array (
@@ -917,14 +938,20 @@ def validate_coerce(self, v):
917
938
v = v_array
918
939
elif self .array_ok and is_simple_array (v ):
919
940
# Check integer type
920
- invalid_els = [e for e in v if not isinstance (e , int )]
941
+ invalid_els = [
942
+ e for e in v if not isinstance (e , int ) and e not in self .extras
943
+ ]
921
944
922
945
if invalid_els :
923
946
self .raise_invalid_elements (invalid_els [:10 ])
924
947
925
948
# Check min/max
926
949
if self .has_min_max :
927
- invalid_els = [e for e in v if not (self .min_val <= e <= self .max_val )]
950
+ invalid_els = [
951
+ e
952
+ for e in v
953
+ if not (self .min_val <= e <= self .max_val ) and e not in self .extras
954
+ ]
928
955
929
956
if invalid_els :
930
957
self .raise_invalid_elements (invalid_els [:10 ])
0 commit comments