Skip to content

Commit aa61e3f

Browse files
JessicaS11weiji14
andauthored
manually remove 'z' from datetime string (#294)
Xarray/pandas/numpy no longer automatically handle datetimes brought in with a timezone ('Z' at the end of the datetime string). This provides a fix by checking and manually removing the last character of the datetime string if it's a Z. Co-authored-by: Wei Ji <[email protected]>
1 parent 768c520 commit aa61e3f

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

doc/source/user_guide/documentation/classes_dev_uml.svg

+3-3
Loading

icepyx/core/read.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,21 @@ def _add_var_to_ds(is2ds, ds, grp_path, wanted_groups_tiered, wanted_dict):
363363
pass
364364

365365
try:
366-
# DevNote: these lines may cause a NumPy Warning, as explained here: https://numpy.org/doc/stable/release/1.11.0-notes.html?
367-
# The below line will silence this warning...
368-
# warnings.filterwarnings(
369-
# "default", category=DeprecationWarning, module=np.astype()
370-
# )
371-
is2ds["data_start_utc"] = is2ds.data_start_utc.astype(np.datetime64)
372-
is2ds["data_end_utc"] = is2ds.data_end_utc.astype(np.datetime64)
366+
if (
367+
hasattr(is2ds, "data_start_utc")
368+
and is2ds["data_start_utc"].data[0].astype(str).endswith("Z")
369+
):
370+
# manually remove 'Z' from datetime to allow conversion to np.datetime64 object (support for timezones is deprecated and causes a seg fault)
371+
is2ds["data_start_utc"] = np.datetime64(
372+
is2ds.data_start_utc.data[0].astype(str)[:-1]
373+
)
374+
is2ds["data_end_utc"] = np.datetime64(
375+
is2ds.data_end_utc.data[0].astype(str)[:-1]
376+
)
377+
else:
378+
is2ds["data_start_utc"] = is2ds.data_start_utc.astype(np.datetime64)
379+
is2ds["data_end_utc"] = is2ds.data_end_utc.astype(np.datetime64)
380+
373381
except AttributeError:
374382
pass
375383

0 commit comments

Comments
 (0)