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

Method validate_coerce

_plotly_utils/basevalidators.py:1364–1403  ·  view source on GitHub ↗
(self, v, should_raise=True)

Source from the content-addressed store, hash-verified

1362 return valid_color_description
1363
1364 def validate_coerce(self, v, should_raise=True):
1365 if is_none_or_typed_array_spec(v):
1366 pass
1367 elif self.array_ok and is_homogeneous_array(v):
1368 v = copy_to_readonly_numpy_array(v)
1369 if self.numbers_allowed() and v.dtype.kind in ["u", "i", "f"]:
1370 # Numbers are allowed and we have an array of numbers.
1371 # All good
1372 pass
1373 else:
1374 validated_v = [self.validate_coerce(e, should_raise=False) for e in v]
1375
1376 invalid_els = self.find_invalid_els(v, validated_v)
1377
1378 if invalid_els and should_raise:
1379 self.raise_invalid_elements(invalid_els)
1380
1381 # ### Check that elements have valid colors types ###
1382 elif self.numbers_allowed() or invalid_els:
1383 v = copy_to_readonly_numpy_array(validated_v, kind="O")
1384 else:
1385 v = copy_to_readonly_numpy_array(validated_v, kind="U")
1386 elif self.array_ok and is_simple_array(v):
1387 validated_v = [self.validate_coerce(e, should_raise=False) for e in v]
1388
1389 invalid_els = self.find_invalid_els(v, validated_v)
1390
1391 if invalid_els and should_raise:
1392 self.raise_invalid_elements(invalid_els)
1393 else:
1394 v = validated_v
1395 else:
1396 # Validate scalar color
1397 validated_v = self.vc_scalar(v)
1398 if validated_v is None and should_raise:
1399 self.raise_invalid_val(v)
1400
1401 v = validated_v
1402
1403 return v
1404
1405 def find_invalid_els(self, orig, validated, invalid_els=None):
1406 """

Callers

nothing calls this directly

Calls 9

numbers_allowedMethod · 0.95
find_invalid_elsMethod · 0.95
vc_scalarMethod · 0.95
is_homogeneous_arrayFunction · 0.85
is_simple_arrayFunction · 0.85
raise_invalid_valMethod · 0.80

Tested by

no test coverage detected