MCPcopy Index your code
hub / github.com/plotly/plotly.py / validate_coerce

Method validate_coerce

_plotly_utils/basevalidators.py:916–978  ·  view source on GitHub ↗
(self, v)

Source from the content-addressed store, hash-verified

914 return desc
915
916 def validate_coerce(self, v):
917 if is_none_or_typed_array_spec(v):
918 pass
919 elif v in self.extras:
920 return v
921 elif self.array_ok and is_homogeneous_array(v):
922 np = get_module("numpy")
923 v_array = copy_to_readonly_numpy_array(
924 v, kind=("i", "u"), force_numeric=True
925 )
926
927 if v_array.dtype.kind not in ["i", "u"]:
928 self.raise_invalid_val(v)
929
930 # Check min/max
931 if self.has_min_max:
932 v_valid = np.logical_and(
933 self.min_val <= v_array, v_array <= self.max_val
934 )
935
936 if not np.all(v_valid):
937 # Grab up to the first 10 invalid values
938 v_invalid = np.logical_not(v_valid)
939 some_invalid_els = np.array(v, dtype="object")[v_invalid][
940 :10
941 ].tolist()
942 self.raise_invalid_elements(some_invalid_els)
943
944 v = v_array
945 elif self.array_ok and is_simple_array(v):
946 # Check integer type
947 invalid_els = [
948 e for e in v if not isinstance(e, int) and e not in self.extras
949 ]
950
951 if invalid_els:
952 self.raise_invalid_elements(invalid_els[:10])
953
954 # Check min/max
955 if self.has_min_max:
956 invalid_els = [
957 e
958 for e in v
959 if not (isinstance(e, int) and self.min_val <= e <= self.max_val)
960 and e not in self.extras
961 ]
962
963 if invalid_els:
964 self.raise_invalid_elements(invalid_els[:10])
965
966 v = to_scalar_or_list(v)
967 else:
968 # Check int
969 if not isinstance(v, int):
970 # don't let int() cast strings to ints
971 self.raise_invalid_val(v)
972
973 # Check min/max

Callers

nothing calls this directly

Calls 10

get_moduleFunction · 0.90
is_homogeneous_arrayFunction · 0.85
is_simple_arrayFunction · 0.85
to_scalar_or_listFunction · 0.85
raise_invalid_valMethod · 0.80
tolistMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected