From 602c3cf3caa94883e1e4fa6957770947ee5595fa Mon Sep 17 00:00:00 2001 From: Michael Niklas Date: Fri, 12 Jul 2024 23:34:03 +0200 Subject: [PATCH] fix some checks --- xarray/core/resample_cftime.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xarray/core/resample_cftime.py b/xarray/core/resample_cftime.py index fcdeb6d8021..a048e85b4d4 100644 --- a/xarray/core/resample_cftime.py +++ b/xarray/core/resample_cftime.py @@ -124,10 +124,10 @@ def __init__( if offset is not None: try: self.offset = _convert_offset_to_timedelta(offset) - except (AttributeError, TypeError) as error: + except (ValueError, TypeError) as error: raise ValueError( f"offset must be a datetime.timedelta object or an offset string " - f"that can be converted to a timedelta. Got {type(offset)} instead." + f"that can be converted to a timedelta. Got {type(offset)} instead." ) from error else: self.offset = None @@ -505,8 +505,8 @@ def _convert_offset_to_timedelta( return offset if isinstance(offset, (str, Tick)): timedelta_cftime_offset = to_offset(offset) - assert isinstance(timedelta_cftime_offset, Tick) - return timedelta_cftime_offset.as_timedelta() + if isinstance(timedelta_cftime_offset, Tick): + return timedelta_cftime_offset.as_timedelta() raise TypeError(f"Expected timedelta, str or Tick, got {type(offset)}")