Fix bug instruments/readers/structured_file_reader.py. pd.to_dict return a list of dicts so we need to handle each item seprately using a loop.

This commit is contained in:
2025-06-07 19:14:53 +02:00
parent f640205b12
commit 83cec97e83

View File

@ -53,20 +53,22 @@ def read_structured_file_as_dict(path_to_file):
logging.error("Failed to normalize data structure: %s", exc) logging.error("Failed to normalize data structure: %s", exc)
raise raise
for item_idx, item in enumerate(df.to_dict(orient='records')):
try: try:
structured_array = utils.convert_attrdict_to_np_structured_array(df.to_dict(orient='records')) structured_array = utils.convert_attrdict_to_np_structured_array(item)
except Exception as exc: except Exception as exc:
logging.error("Failed to convert to structured array: %s", exc) logging.error("Failed to convert to structured array: %s", exc)
raise raise
dataset = { dataset = {
'name': 'data_table', 'name': f'data_table_{item_idx}',
'data': structured_array, 'data': structured_array,
'shape': structured_array.shape, 'shape': structured_array.shape,
'dtype': type(structured_array) 'dtype': type(structured_array)
} }
file_dict['datasets'].append(dataset) file_dict['datasets'].append(dataset)
return file_dict return file_dict
if __name__ == "__main__": if __name__ == "__main__":