From 922a9b3feaf108f44ca1de62aae0a560309f34b3 Mon Sep 17 00:00:00 2001 From: Baudouin Raoult Date: Sat, 1 Jun 2024 15:49:58 +0000 Subject: [PATCH] fix bug when adjusting start/end of datasets --- src/anemoi/datasets/data/misc.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/anemoi/datasets/data/misc.py b/src/anemoi/datasets/data/misc.py index dbc1946c..3f8b1ad9 100644 --- a/src/anemoi/datasets/data/misc.py +++ b/src/anemoi/datasets/data/misc.py @@ -88,13 +88,12 @@ def _frequency_to_hours(frequency): def _as_date(d, dates, last): - if isinstance(d, np.datetime64): - d = d.astype(datetime.datetime) - if isinstance(d, datetime.datetime): - if not d.minute == 0 and d.hour == 0 and d.second == 0: - return np.datetime64(d) - d = datetime.date(d.year, d.month, d.day) + # WARNING, datetime.datetime is a subclass of datetime.date + # so we need to check for datetime.datetime first + + if isinstance(d, (np.datetime64, datetime.datetime)): + return d if isinstance(d, datetime.date): d = d.year * 10_000 + d.month * 100 + d.day