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

Method validate_coerce

_plotly_utils/basevalidators.py:2632–2696  ·  view source on GitHub ↗
(self, v, skip_invalid=False, _validate=True)

Source from the content-addressed store, hash-verified

2630 return self._class_map[trace_name]
2631
2632 def validate_coerce(self, v, skip_invalid=False, _validate=True):
2633 from plotly.basedatatypes import BaseTraceType
2634
2635 # Import Histogram2dcontour, this is the deprecated name of the
2636 # Histogram2dContour trace.
2637 from plotly.graph_objs import Histogram2dcontour
2638
2639 if v is None:
2640 v = []
2641 else:
2642 if not isinstance(v, (list, tuple)):
2643 v = [v]
2644
2645 res = []
2646 invalid_els = []
2647 for v_el in v:
2648 if isinstance(v_el, BaseTraceType):
2649 if isinstance(v_el, Histogram2dcontour):
2650 v_el = dict(type="histogram2dcontour", **v_el._props)
2651 else:
2652 v_el = v_el._props
2653
2654 if isinstance(v_el, dict):
2655 type_in_v_el = "type" in v_el
2656 trace_type = v_el.pop("type", "scatter")
2657
2658 if trace_type not in self.class_strs_map:
2659 if skip_invalid:
2660 # Treat as scatter trace
2661 trace = self.get_trace_class("scatter")(
2662 skip_invalid=skip_invalid, _validate=_validate, **v_el
2663 )
2664 res.append(trace)
2665 else:
2666 res.append(None)
2667 invalid_els.append(v_el)
2668 else:
2669 trace = self.get_trace_class(trace_type)(
2670 skip_invalid=skip_invalid, _validate=_validate, **v_el
2671 )
2672 res.append(trace)
2673
2674 if type_in_v_el:
2675 # Restore type in v_el
2676 v_el["type"] = trace_type
2677 else:
2678 if skip_invalid:
2679 # Add empty scatter trace
2680 trace = self.get_trace_class("scatter")()
2681 res.append(trace)
2682 else:
2683 res.append(None)
2684 invalid_els.append(v_el)
2685
2686 if invalid_els:
2687 self.raise_invalid_elements(invalid_els)
2688
2689 v = to_scalar_or_list(res)

Callers

nothing calls this directly

Calls 4

get_trace_classMethod · 0.95
to_scalar_or_listFunction · 0.85
popMethod · 0.45

Tested by

no test coverage detected