diff --git a/preprocessing/nextclade/src/loculus_preprocessing/processing_functions.py b/preprocessing/nextclade/src/loculus_preprocessing/processing_functions.py index c04c63793..cc63d6229 100644 --- a/preprocessing/nextclade/src/loculus_preprocessing/processing_functions.py +++ b/preprocessing/nextclade/src/loculus_preprocessing/processing_functions.py @@ -232,8 +232,6 @@ def parse_date_into_range( errors=[], ) - logger.debug(f"release_date: {release_date}") - formats_to_messages = { "%Y-%m-%d": None, "%Y-%m": "Day is missing. Assuming date is some time in the month.", @@ -277,12 +275,6 @@ class DateRange: date_range_lower=parsed_date.replace(month=1, day=1), date_range_upper=parsed_date.replace(month=12, day=31), ) - case "_": - datum = DateRange( - date_range_string=None, - date_range_lower=None, - date_range_upper=max_upper_limit, - ) logger.debug(f"parsed_date: {datum}") diff --git a/preprocessing/nextclade/tests/test_processing_functions.py b/preprocessing/nextclade/tests/test_processing_functions.py index 6305baaef..3763a5585 100644 --- a/preprocessing/nextclade/tests/test_processing_functions.py +++ b/preprocessing/nextclade/tests/test_processing_functions.py @@ -483,27 +483,73 @@ def test_format_authors() -> None: raise AssertionError(msg) -def test_parse_date_into_range(): - assert ProcessingFunctions.parse_date_into_range( - {"date": "2021-12"}, "field_name", {"fieldType": "dateRangeString"} - ), "2021-12" - assert ProcessingFunctions.parse_date_into_range( - {"date": "2021-12"}, "field_name", {"fieldType": "dateRangeLower"} - ), "2021-12-01" - assert ProcessingFunctions.parse_date_into_range( - {"date": "2021-12"}, "field_name", {"fieldType": "dateRangeUpper"} - ), "2021-12-31" - assert ProcessingFunctions.parse_date_into_range( - {"date": "2021-02"}, "field_name", {"fieldType": "dateRangeUpper"} - ), "2021-02-28" - assert ProcessingFunctions.parse_date_into_range( - {"date": "2021"}, "field_name", {"fieldType": "dateRangeUpper"} - ), "2021-12-31" - assert ProcessingFunctions.parse_date_into_range( - {"date": "2021-12", "releaseDate": "2021-12-15"}, - "field_name", - {"fieldType": "dateRangeUpper"}, - ), "2021-12-15" +def test_parse_date_into_range() -> None: + assert ( + ProcessingFunctions.parse_date_into_range( + {"date": "2021-12"}, "field_name", {"fieldType": "dateRangeString"} + ).datum + == "2021-12" + ), "dateRangeString: 2021-12 should be returned as is." + assert ( + ProcessingFunctions.parse_date_into_range( + {"date": "2021-12"}, "field_name", {"fieldType": "dateRangeLower"} + ).datum + == "2021-12-01" + ), "dateRangeLower: 2021-12 should be returned as 2021-12-01." + assert ( + ProcessingFunctions.parse_date_into_range( + {"date": "2021-12"}, "field_name", {"fieldType": "dateRangeUpper"} + ).datum + == "2021-12-31" + ), "dateRangeUpper: 2021-12 should be returned as 2021-12-31." + assert ( + ProcessingFunctions.parse_date_into_range( + {"date": "2021-02"}, "field_name", {"fieldType": "dateRangeUpper"} + ).datum + == "2021-02-28" + ), "dateRangeUpper: 2021-02 should be returned as 2021-02-28." + assert ( + ProcessingFunctions.parse_date_into_range( + {"date": "2021"}, "field_name", {"fieldType": "dateRangeUpper"} + ).datum + == "2021-12-31" + ), "dateRangeUpper: 2021 should be returned as 2021-12-31." + assert ( + ProcessingFunctions.parse_date_into_range( + {"date": "2021-12", "releaseDate": "2021-12-15"}, + "field_name", + {"fieldType": "dateRangeUpper"}, + ).datum + == "2021-12-15" + ), "dateRangeUpper: 2021-12 with releaseDate 2021-12-15 should be returned as 2021-12-15." + assert ( + ProcessingFunctions.parse_date_into_range( + {"date": "", "releaseDate": "2021-12-15"}, + "field_name", + {"fieldType": "dateRangeUpper"}, + ).datum + == "2021-12-15" + ), "dateRangeUpper: empty date with releaseDate 2021-12-15 should be returned as 2021-12-15." + assert ( + ProcessingFunctions.parse_date_into_range( + {"date": ""}, "field_name", {"fieldType": "dateRangeString"} + ).datum + is None + ), "dateRangeString: empty date should be returned as None." + assert ( + ProcessingFunctions.parse_date_into_range( + {"date": "not.date"}, "field_name", {"fieldType": "dateRangeString"} + ).datum + is None + ), "dateRangeString: invalid date should be returned as None." + assert ( + ProcessingFunctions.parse_date_into_range( + {"date": "", "releaseDate": "2021-12-15"}, + "field_name", + {"fieldType": "dateRangeLower"}, + ).datum + is None + ), "dateRangeLower: empty date should be returned as None." if __name__ == "__main__":