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

Method validate_coerce

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

Source from the content-addressed store, hash-verified

1603 return desc
1604
1605 def validate_coerce(self, v):
1606 v_valid = False
1607
1608 if v is None:
1609 v_valid = True
1610 elif isinstance(v, str):
1611 v_lower = v.lower()
1612 if v_lower in self.named_colorscales:
1613 # Convert to color list
1614 v = self.named_colorscales[v_lower]
1615 v_valid = True
1616 elif v_lower.endswith("_r") and v_lower[:-2] in self.named_colorscales:
1617 v = self.named_colorscales[v_lower[:-2]][::-1]
1618 v_valid = True
1619 #
1620 if v_valid:
1621 # Convert to list of lists colorscale
1622 d = len(v) - 1
1623 v = [[(1.0 * i) / (1.0 * d), x] for i, x in enumerate(v)]
1624
1625 elif is_array(v) and len(v) > 0:
1626 # If firset element is a string, treat as colorsequence
1627 if isinstance(v[0], str):
1628 invalid_els = [
1629 e for e in v if ColorValidator.perform_validate_coerce(e) is None
1630 ]
1631
1632 if len(invalid_els) == 0:
1633 v_valid = True
1634
1635 # Convert to list of lists colorscale
1636 d = len(v) - 1
1637 v = [[(1.0 * i) / (1.0 * d), x] for i, x in enumerate(v)]
1638 else:
1639 invalid_els = [
1640 e
1641 for e in v
1642 if (
1643 not is_array(e)
1644 or len(e) != 2
1645 or not isinstance(e[0], numbers.Number)
1646 or not (0 <= e[0] <= 1)
1647 or not isinstance(e[1], str)
1648 or ColorValidator.perform_validate_coerce(e[1]) is None
1649 )
1650 ]
1651
1652 if len(invalid_els) == 0:
1653 v_valid = True
1654
1655 # Convert to list of lists
1656 v = [
1657 [e[0], ColorValidator.perform_validate_coerce(e[1])] for e in v
1658 ]
1659
1660 if not v_valid:
1661 self.raise_invalid_val(v)
1662

Callers 2

make_figureFunction · 0.95
imshowFunction · 0.95

Calls 3

is_arrayFunction · 0.85
raise_invalid_valMethod · 0.80

Tested by

no test coverage detected