From 356d4ef7772cc373d43ef43d1c28b663ddeab576 Mon Sep 17 00:00:00 2001 From: Eric Denovellis Date: Fri, 28 Apr 2023 14:30:14 -0700 Subject: [PATCH] Convert DOB from datetime object to string --- .../processing/metadata/metadata_extractor.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/rec_to_nwb/processing/metadata/metadata_extractor.py b/rec_to_nwb/processing/metadata/metadata_extractor.py index 4dcea3b8..d1e78230 100644 --- a/rec_to_nwb/processing/metadata/metadata_extractor.py +++ b/rec_to_nwb/processing/metadata/metadata_extractor.py @@ -4,11 +4,15 @@ class MetadataExtractor: - @staticmethod def extract_metadata(metadata_path): - with open(metadata_path, 'r') as stream: - return json.loads( - json.dumps(yaml.safe_load(stream)), - parse_int=str, - parse_float=str) + with open(metadata_path, "r") as stream: + yaml_dict = yaml.safe_load(stream) + + # yaml automatically converts date_of_birth to a datetime object, need to convert back + yaml_dict["subject"]["date_of_birth"] = yaml_dict["subject"][ + "date_of_birth" + ].strftime("%Y-%m-%dT%H:%M:%S.%fZ") + + # for some reason they want to convert all ints, float to strings + return json.loads(json.dumps(yaml_dict), parse_int=str, parse_float=str)