From 83cec97e8363f7a24f5522ecdb55ff1c5b6b6af4 Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Sat, 7 Jun 2025 19:14:53 +0200 Subject: [PATCH] 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. --- instruments/readers/structured_file_reader.py | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/instruments/readers/structured_file_reader.py b/instruments/readers/structured_file_reader.py index 5c16281..094c6ab 100644 --- a/instruments/readers/structured_file_reader.py +++ b/instruments/readers/structured_file_reader.py @@ -53,20 +53,22 @@ def read_structured_file_as_dict(path_to_file): logging.error("Failed to normalize data structure: %s", exc) raise - try: - structured_array = utils.convert_attrdict_to_np_structured_array(df.to_dict(orient='records')) - except Exception as exc: - logging.error("Failed to convert to structured array: %s", exc) - raise + for item_idx, item in enumerate(df.to_dict(orient='records')): + try: + structured_array = utils.convert_attrdict_to_np_structured_array(item) + except Exception as exc: + logging.error("Failed to convert to structured array: %s", exc) + raise - dataset = { - 'name': 'data_table', - 'data': structured_array, - 'shape': structured_array.shape, - 'dtype': type(structured_array) - } + dataset = { + 'name': f'data_table_{item_idx}', + 'data': structured_array, + 'shape': structured_array.shape, + 'dtype': type(structured_array) + } - file_dict['datasets'].append(dataset) + file_dict['datasets'].append(dataset) + return file_dict if __name__ == "__main__":