@@ -41,11 +41,13 @@ def convert_results_to_dataframe(
41
41
- Properties: All the properties will be split into separate columns. For example,
42
42
properties.property1, properties.property2, etc.
43
43
"""
44
- results_dict = [result .dict (exclude_none = True ) for result in results ]
45
- results_dict_with_normalized_status = __normalize_results_status (results_dict )
46
- normalized_dataframe = pd .json_normalize (
47
- results_dict_with_normalized_status , sep = "."
48
- )
44
+ results_dict = []
45
+ for result in results :
46
+ data = result .dict (exclude_none = True )
47
+ __normalize_status (data )
48
+ results_dict .append (data )
49
+
50
+ normalized_dataframe = pd .json_normalize (results_dict , sep = "." )
49
51
normalized_dataframe = __format_results_columns (
50
52
results_dataframe = normalized_dataframe
51
53
)
@@ -98,26 +100,20 @@ def convert_steps_to_dataframe(
98
100
return steps_dataframe .reindex (columns = grouped_columns , copy = False )
99
101
100
102
101
- def __normalize_results_status (
102
- results_dict : List [ Dict [str , Any ] ],
103
- ) -> List [ Dict [ str , Any ]] :
104
- """Gets dictionary of results data and modifies the status object.
103
+ def __normalize_status (
104
+ data : Dict [str , Any ],
105
+ ) -> None :
106
+ """Normalizes the status object into a string .
105
107
106
108
Args:
107
- results: List of results .
109
+ data: Dictionary containing status information .
108
110
109
- Returns:
110
- A list of result fields as dictionary. If status.status_type is "CUSTOM"
111
- the status field takes the value of "status_name", else value of "status_type" is used.
112
111
"""
113
- for result in results_dict :
114
- status = result .get ("status" , {})
115
- if status .get ("status_type" ) == "CUSTOM" :
116
- result ["status" ] = status ["status_name" ]
117
- else :
118
- result ["status" ] = status ["status_type" ].value
119
-
120
- return results_dict
112
+ status = data .get ("status" , {})
113
+ if status .get ("status_type" ) == "CUSTOM" :
114
+ data ["status" ] = status .get ("status_name" , None )
115
+ else :
116
+ data ["status" ] = getattr (status .get ("status_type" , None ), "value" , None )
121
117
122
118
123
119
def __format_results_columns (results_dataframe : pd .DataFrame ) -> pd .DataFrame :
@@ -208,7 +204,7 @@ def __convert_steps_to_dict(
208
204
single_step_dict = step .dict (exclude_none = True )
209
205
__filter_invalid_measurements (single_step_dict , step , is_valid_measurement )
210
206
__normalize_inputs_outputs (single_step_dict , step )
211
- __normalize_step_status (single_step_dict )
207
+ __normalize_status (single_step_dict )
212
208
steps_dict .append (single_step_dict )
213
209
return steps_dict
214
210
@@ -266,24 +262,6 @@ def __normalize_inputs_outputs(
266
262
)
267
263
268
264
269
- def __normalize_step_status (step_dict : Dict [str , Any ]) -> None :
270
- """Normalizes the step status field. If status_type is "CUSTOM",
271
- then status.status_name is used, else status.status_type.value is assigned.
272
-
273
- Args:
274
- step_dict: A dictionary with step information.
275
-
276
- Returns:
277
- None: The function modifies step_dict in place with the normalized step
278
- """
279
- step_status = step_dict .get ("status" , {})
280
- step_dict ["status" ] = (
281
- step_status .get ("status_name" , None )
282
- if step_status .get ("status_type" ) == "CUSTOM"
283
- else step_status .get ("status_type" , None ).value
284
- )
285
-
286
-
287
265
def __explode_and_normalize (
288
266
dataframe : pd .DataFrame , column : str , prefix : str
289
267
) -> pd .DataFrame :
0 commit comments