@@ -41,11 +41,13 @@ def convert_results_to_dataframe(
4141 - Properties: All the properties will be split into separate columns. For example,
4242 properties.property1, properties.property2, etc.
4343 """
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 = "." )
4951 normalized_dataframe = __format_results_columns (
5052 results_dataframe = normalized_dataframe
5153 )
@@ -98,26 +100,20 @@ def convert_steps_to_dataframe(
98100 return steps_dataframe .reindex (columns = grouped_columns , copy = False )
99101
100102
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 .
105107
106108 Args:
107- results: List of results .
109+ data: Dictionary containing status information .
108110
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.
112111 """
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 )
121117
122118
123119def __format_results_columns (results_dataframe : pd .DataFrame ) -> pd .DataFrame :
@@ -208,7 +204,7 @@ def __convert_steps_to_dict(
208204 single_step_dict = step .dict (exclude_none = True )
209205 __filter_invalid_measurements (single_step_dict , step , is_valid_measurement )
210206 __normalize_inputs_outputs (single_step_dict , step )
211- __normalize_step_status (single_step_dict )
207+ __normalize_status (single_step_dict )
212208 steps_dict .append (single_step_dict )
213209 return steps_dict
214210
@@ -266,24 +262,6 @@ def __normalize_inputs_outputs(
266262 )
267263
268264
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-
287265def __explode_and_normalize (
288266 dataframe : pd .DataFrame , column : str , prefix : str
289267) -> pd .DataFrame :
0 commit comments