@@ -87,8 +87,8 @@ def load_from_stf2_file(file_path: str, time_zone_timestamps: bool) -> xr.Datase
8787
8888 # work around https://jira.csiro.au/browse/WIRADA-635
8989 # lead_time can be a problem with xarray, so do not decode "times"
90- x = xr.open_dataset(file_path, decode_times =False)
91-
90+ # we also use mask_and_scale =False because of https://github.com/csiro-hydroinformatics/efts-io/issues/24
91+ x = xr.open_dataset(file_path, decode_times=False, mask_and_scale=False)
9292 # replace the time and station names coordinates values
9393 # TODO This is probably not a long term solution for round-tripping a read/write or vice and versa
9494 decod = times.CFDatetimeCoder(use_cftime=True)
@@ -181,11 +181,19 @@ def __init__(self, data: Union[str, xr.Dataset]) -> None:
181181 self.ENS_MEMBER_DIMNAME = ENS_MEMBER_DIMNAME
182182 # self.identifiers_dimensions: list = []
183183 self.data: xr.Dataset
184+ from pathlib import Path
185+
186+ if data is None:
187+ raise ValueError("input cannot be None")
188+ if isinstance(data, Path):
189+ data = str(data)
184190 if isinstance(data, str):
185191 new_dataset = load_from_stf2_file(data, self.time_zone_timestamps)
186192 self.data = new_dataset
187- else :
193+ elif isinstance(data, xr.Dataset) :
188194 self.data = data
195+ else:
196+ raise TypeError(f"Unsupported type {type(data)}")
189197
190198 self.stf2_int_datatype = "i4" # default integer type for STF2 saving
191199
@@ -275,8 +283,10 @@ def append_history(self, message: str, timestamp: Optional[datetime] = None) ->
275283 message: The message to append.
276284 timestamp: If not provided, the current UTC time is used.
277285 """
286+ from datetime import UTC
287+
278288 if timestamp is None:
279- timestamp = datetime.now(datetime.timezone.utc ).isoformat()
289+ timestamp = datetime.now(UTC ).isoformat()
280290
281291 current_history = self.data.attrs.get(HISTORY_ATTR_KEY, "")
282292 if current_history:
0 commit comments