From 84d04db46462c9e7c054503e4487fa96d6946d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Mon, 14 Oct 2024 16:32:09 +0200 Subject: [PATCH] fix for reading heads using ds when no time has been set - default to float time index - fix for minor error introduced in #375 --- nlmod/mfoutput/mfoutput.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nlmod/mfoutput/mfoutput.py b/nlmod/mfoutput/mfoutput.py index 0e98c874..906f9d34 100644 --- a/nlmod/mfoutput/mfoutput.py +++ b/nlmod/mfoutput/mfoutput.py @@ -71,12 +71,18 @@ def _get_time_index(fobj, ds=None, gwf_or_gwt=None): time_units=gwf_or_gwt.modeltime.time_units, ) elif ds is not None: + if "time" in ds: + dtype = "float" if ds.time.dtype.kind in ["i", "f"] else "datetime" + else: + dtype = "float" tindex = ds_time_idx( fobj.get_times(), start_datetime=(ds.time.attrs["start"] if "time" in ds else None), time_units=(ds.time.attrs["time_units"] if "time" in ds else None), - dtype="float" if ds.time.dtype.kind in ["i", "f"] else "datetime", + dtype=dtype, ) + else: + raise ValueError("Provide either ds or gwf_or_gwt") return tindex