@@ -112,42 +112,45 @@ def __init__(
112112 ):
113113 super ().__init__ (plot_id , data , properties )
114114 self .plot_id = plot_id
115- self .inferred_properties : Dict = {}
116115
117116 def _infer_y_from_data (self ):
118117 if self .plot_id in self .data :
119118 for lst in _lists (self .data [self .plot_id ]):
120119 if all (isinstance (item , dict ) for item in lst ):
121120 datapoint = first (lst )
122121 field = last (datapoint .keys ())
123- self . inferred_properties [ "y" ] = {self .plot_id : field }
124- break
122+ return {self .plot_id : field }
123+ return None
125124
126125 def _infer_x_y (self ):
127126 x = self .properties .get ("x" , None )
128127 y = self .properties .get ("y" , None )
129128
129+ inferred_properties : Dict = {}
130+
130131 # Infer x.
131132 if isinstance (x , str ):
132- self . inferred_properties ["x" ] = {}
133+ inferred_properties ["x" ] = {}
133134 # If multiple y files, duplicate x for each file.
134135 if isinstance (y , dict ):
135136 for file , fields in y .items ():
136137 # Duplicate x for each y.
137138 if isinstance (fields , list ):
138- self . inferred_properties ["x" ][file ] = [x ] * len (fields )
139+ inferred_properties ["x" ][file ] = [x ] * len (fields )
139140 else :
140- self . inferred_properties ["x" ][file ] = x
141+ inferred_properties ["x" ][file ] = x
141142 # Otherwise use plot ID as file.
142143 else :
143- self . inferred_properties ["x" ][self .plot_id ] = x
144+ inferred_properties ["x" ][self .plot_id ] = x
144145
145146 # Infer y.
146147 if y is None :
147- self ._infer_y_from_data ()
148+ inferred_properties [ "y" ] = self ._infer_y_from_data ()
148149 # If y files not provided, use plot ID as file.
149150 elif not isinstance (y , dict ):
150- self .inferred_properties ["y" ] = {self .plot_id : y }
151+ inferred_properties ["y" ] = {self .plot_id : y }
152+
153+ return inferred_properties
151154
152155 def _find_datapoints (self ):
153156 result = {}
@@ -303,10 +306,10 @@ def convert(
303306 generated datapoints and updated properties. `x`, `y` values and labels
304307 are inferred and always provided.
305308 """
306- self ._infer_x_y ()
309+ inferred_properties = self ._infer_x_y ()
307310
308311 datapoints = self ._find_datapoints ()
309- properties = {** self .properties , ** self . inferred_properties }
312+ properties = {** self .properties , ** inferred_properties }
310313
311314 properties ["y_label" ] = self .infer_y_label (properties )
312315 properties ["x_label" ] = self .infer_x_label (properties )
0 commit comments