From 8c4f1725d7bc10b1592b5af02afd084659192078 Mon Sep 17 00:00:00 2001 From: Yingkai Sha Date: Thu, 9 Jan 2025 15:28:56 -0700 Subject: [PATCH 1/2] bugfix on datetime import --- credit/data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/credit/data.py b/credit/data.py index 1bf95a1..2e1a77f 100644 --- a/credit/data.py +++ b/credit/data.py @@ -1320,10 +1320,10 @@ def find_start_stop_indices(self, index): # ============================================================================ # # subtrack shifted_hour form the 1st & last init times # convert to datetime object - self.init_datetime[index][0] = datetime.strptime( + self.init_datetime[index][0] = datetime.datetime.strptime( self.init_datetime[index][0], "%Y-%m-%d %H:%M:%S" ) - timedelta(hours=shifted_hours) - self.init_datetime[index][1] = datetime.strptime( + self.init_datetime[index][1] = datetime.datetime.strptime( self.init_datetime[index][1], "%Y-%m-%d %H:%M:%S" ) - timedelta(hours=shifted_hours) From 403bacd29c4ca97789aea5a46cdf1c21a43a0fa1 Mon Sep 17 00:00:00 2001 From: Yingkai Sha Date: Thu, 9 Jan 2025 15:51:37 -0700 Subject: [PATCH 2/2] more bugfix on the use of datetime --- credit/data.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/credit/data.py b/credit/data.py index 2e1a77f..8072ffc 100644 --- a/credit/data.py +++ b/credit/data.py @@ -1322,10 +1322,10 @@ def find_start_stop_indices(self, index): # convert to datetime object self.init_datetime[index][0] = datetime.datetime.strptime( self.init_datetime[index][0], "%Y-%m-%d %H:%M:%S" - ) - timedelta(hours=shifted_hours) + ) - datetime.timedelta(hours=shifted_hours) self.init_datetime[index][1] = datetime.datetime.strptime( self.init_datetime[index][1], "%Y-%m-%d %H:%M:%S" - ) - timedelta(hours=shifted_hours) + ) - datetime.timedelta(hours=shifted_hours) # convert the 1st & last init times to a list of init times self.init_datetime[index] = generate_datetime( @@ -1343,7 +1343,7 @@ def find_start_stop_indices(self, index): # init_time_list_np[0]: the first initialization time # init_time_list_np[t]: the forcasted time of the (t-1)th step; the initialization time of the t-th step self.init_time_list_np = [ - np.datetime64(str(dt_obj) + ".000000000").astype(datetime) + np.datetime64(str(dt_obj) + ".000000000").astype(datetime.datetime) for dt_obj in init_time_list_dt ] @@ -1361,7 +1361,7 @@ def find_start_stop_indices(self, index): N_times = len(ds["time"]) # convert ds['time'] to a list of nanosecondes ds_time_list = [ - np.datetime64(ds_time.values).astype(datetime) + np.datetime64(ds_time.values).astype(datetime.datetime) for ds_time in ds["time"] ] ds_start_time = ds_time_list[0]