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

Method validate_coerce

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

Source from the content-addressed store, hash-verified

771 return desc
772
773 def validate_coerce(self, v):
774 if is_none_or_typed_array_spec(v):
775 pass
776 elif self.array_ok and is_homogeneous_array(v):
777 np = get_module("numpy")
778 try:
779 v_array = copy_to_readonly_numpy_array(v, force_numeric=True)
780 except (ValueError, TypeError, OverflowError):
781 self.raise_invalid_val(v)
782
783 # Check min/max
784 if self.has_min_max:
785 v_valid = np.logical_and(
786 self.min_val <= v_array, v_array <= self.max_val
787 )
788
789 if not np.all(v_valid):
790 # Grab up to the first 10 invalid values
791 v_invalid = np.logical_not(v_valid)
792 some_invalid_els = np.array(v, dtype="object")[v_invalid][
793 :10
794 ].tolist()
795
796 self.raise_invalid_elements(some_invalid_els)
797
798 v = v_array # Always numeric numpy array
799 elif self.array_ok and is_simple_array(v):
800 # Check numeric
801 invalid_els = [e for e in v if not isinstance(e, numbers.Number)]
802
803 if invalid_els:
804 self.raise_invalid_elements(invalid_els[:10])
805
806 # Check min/max
807 if self.has_min_max:
808 invalid_els = [e for e in v if not (self.min_val <= e <= self.max_val)]
809
810 if invalid_els:
811 self.raise_invalid_elements(invalid_els[:10])
812
813 v = to_scalar_or_list(v)
814 else:
815 # Check numeric
816 if not isinstance(v, numbers.Number):
817 self.raise_invalid_val(v)
818
819 # Check min/max
820 if self.has_min_max:
821 if not (self.min_val <= v <= self.max_val):
822 self.raise_invalid_val(v)
823 return v
824
825
826class IntegerValidator(BaseValidator):

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