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

Method validate_coerce

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

Source from the content-addressed store, hash-verified

1075 return desc
1076
1077 def validate_coerce(self, v):
1078 if is_none_or_typed_array_spec(v):
1079 pass
1080 elif self.array_ok and is_array(v):
1081 # If strict, make sure all elements are strings.
1082 if self.strict:
1083 invalid_els = [e for e in v if not isinstance(e, str)]
1084 if invalid_els:
1085 self.raise_invalid_elements(invalid_els)
1086
1087 if is_homogeneous_array(v):
1088 np = get_module("numpy")
1089
1090 # If not strict, let numpy cast elements to strings
1091 v = copy_to_readonly_numpy_array(v, kind="U")
1092
1093 # Check no_blank
1094 if self.no_blank:
1095 invalid_els = v[v == ""][:10].tolist()
1096 if invalid_els:
1097 self.raise_invalid_elements(invalid_els)
1098
1099 # Check values
1100 if self.values:
1101 invalid_inds = np.logical_not(np.isin(v, self.values))
1102 invalid_els = v[invalid_inds][:10].tolist()
1103 if invalid_els:
1104 self.raise_invalid_elements(invalid_els)
1105 elif is_simple_array(v):
1106 if not self.strict:
1107 v = [StringValidator.to_str_or_unicode_or_none(e) for e in v]
1108
1109 # Check no_blank
1110 if self.no_blank:
1111 invalid_els = [e for e in v if e == ""]
1112 if invalid_els:
1113 self.raise_invalid_elements(invalid_els)
1114
1115 # Check values
1116 if self.values:
1117 invalid_els = [e for e in v if v not in self.values]
1118 if invalid_els:
1119 self.raise_invalid_elements(invalid_els)
1120
1121 v = to_scalar_or_list(v)
1122
1123 else:
1124 if self.strict:
1125 if not isinstance(v, str):
1126 self.raise_invalid_val(v)
1127 else:
1128 if isinstance(v, str):
1129 pass
1130 elif isinstance(v, (int, float)):
1131 # Convert value to a string
1132 v = str(v)
1133 else:
1134 self.raise_invalid_val(v)

Callers

nothing calls this directly

Calls 11

get_moduleFunction · 0.90
is_arrayFunction · 0.85
is_homogeneous_arrayFunction · 0.85
is_simple_arrayFunction · 0.85
to_scalar_or_listFunction · 0.85
tolistMethod · 0.80
raise_invalid_valMethod · 0.80

Tested by

no test coverage detected