From ba11b1ed5c070f2bb225aacad1f9a4ea83d698a5 Mon Sep 17 00:00:00 2001 From: Lukas Pilz Date: Tue, 4 Apr 2023 13:34:01 +0200 Subject: [PATCH 1/2] Fixed decoding of timestamp by using more flexible ISO8601 instead of format string --- xwrf/postprocess.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/xwrf/postprocess.py b/xwrf/postprocess.py index 8e8ffda7..a8c33159 100644 --- a/xwrf/postprocess.py +++ b/xwrf/postprocess.py @@ -21,9 +21,7 @@ def _decode_times(ds: xr.Dataset) -> xr.Dataset: ds.Times.data.astype('str'), errors='raise', format='%Y-%m-%d_%H:%M:%S' ) except ValueError: - _time = pd.to_datetime( - ds.Times.data.astype('str'), errors='raise', format='%Y-%m-%dT%H:%M:%S.%f' - ) + _time = pd.to_datetime(ds.Times.data.astype('str'), errors='raise', format='ISO8601') ds = ds.assign_coords({'Time': _time}) ds.Time.attrs = {'long_name': 'Time', 'standard_name': 'time'} # make XTIME be consistent with its description From 262d1d1f6306685e5ba7f8b271a219e372b8b85a Mon Sep 17 00:00:00 2001 From: Lukas Pilz Date: Tue, 4 Apr 2023 13:55:26 +0200 Subject: [PATCH 2/2] Changed format string from ISO8601 because it doesn't work with python 3.9 and 3.10 --- xwrf/postprocess.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xwrf/postprocess.py b/xwrf/postprocess.py index a8c33159..6aafd4d0 100644 --- a/xwrf/postprocess.py +++ b/xwrf/postprocess.py @@ -21,7 +21,9 @@ def _decode_times(ds: xr.Dataset) -> xr.Dataset: ds.Times.data.astype('str'), errors='raise', format='%Y-%m-%d_%H:%M:%S' ) except ValueError: - _time = pd.to_datetime(ds.Times.data.astype('str'), errors='raise', format='ISO8601') + _time = pd.to_datetime( + ds.Times.data.astype('str'), errors='raise', format='%Y-%m-%dT%H:%M:%S' + ) ds = ds.assign_coords({'Time': _time}) ds.Time.attrs = {'long_name': 'Time', 'standard_name': 'time'} # make XTIME be consistent with its description