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

Method _transform_data

plotly/basewidget.py:884–989  ·  view source on GitHub ↗

Transform to_data into from_data and return relayout-style description of the transformation Parameters ---------- to_data : dict|list from_data : dict|list Returns ------- dict relayout-style description of the t

(to_data, from_data, should_remove=True, relayout_path=())

Source from the content-addressed store, hash-verified

882
883 @staticmethod
884 def _transform_data(to_data, from_data, should_remove=True, relayout_path=()):
885 """
886 Transform to_data into from_data and return relayout-style
887 description of the transformation
888
889 Parameters
890 ----------
891 to_data : dict|list
892 from_data : dict|list
893
894 Returns
895 -------
896 dict
897 relayout-style description of the transformation
898 """
899
900 # Initialize relayout data
901 # ------------------------
902 relayout_data = {}
903
904 # Handle dict
905 # -----------
906 if isinstance(to_data, dict):
907 # ### Validate from_data ###
908 if not isinstance(from_data, dict):
909 raise ValueError(
910 "Mismatched data types: {to_dict} {from_data}".format(
911 to_dict=to_data, from_data=from_data
912 )
913 )
914
915 # ### Add/modify properties ###
916 # Loop over props/vals
917 for from_prop, from_val in from_data.items():
918 # #### Handle compound vals recursively ####
919 if isinstance(from_val, dict) or BaseFigure._is_dict_list(from_val):
920 # ##### Init property value if needed #####
921 if from_prop not in to_data:
922 to_data[from_prop] = {} if isinstance(from_val, dict) else []
923
924 # ##### Transform property val recursively #####
925 input_val = to_data[from_prop]
926 relayout_data.update(
927 BaseFigureWidget._transform_data(
928 input_val,
929 from_val,
930 should_remove=should_remove,
931 relayout_path=relayout_path + (from_prop,),
932 )
933 )
934
935 # #### Handle simple vals directly ####
936 else:
937 if from_prop not in to_data or not BasePlotlyType._vals_equal(
938 to_data[from_prop], from_val
939 ):
940 to_data[from_prop] = from_val
941 relayout_path_prop = relayout_path + (from_prop,)

Callers 2

Calls 7

_is_dict_listMethod · 0.80
_vals_equalMethod · 0.80
formatMethod · 0.45
itemsMethod · 0.45
updateMethod · 0.45
keysMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected