Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt exception handling logic in CFTimeIndex.__sub__ and __rsub__ #5006

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions xarray/coding/cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
REPR_ELLIPSIS_SHOW_ITEMS_FRONT_END = 10


if LooseVersion(pd.__version__) > LooseVersion("1.2.3"):
OUT_OF_BOUNDS_TIMEDELTA_ERROR = pd.errors.OutOfBoundsTimedelta
else:
OUT_OF_BOUNDS_TIMEDELTA_ERROR = OverflowError


def named(name, pattern):
return "(?P<" + name + ">" + pattern + ")"

Expand Down Expand Up @@ -562,7 +568,7 @@ def __sub__(self, other):
elif _contains_cftime_datetimes(np.array(other)):
try:
return pd.TimedeltaIndex(np.array(self) - np.array(other))
except OverflowError:
except OUT_OF_BOUNDS_TIMEDELTA_ERROR:
raise ValueError(
"The time difference exceeds the range of values "
"that can be expressed at the nanosecond resolution."
Expand All @@ -573,7 +579,7 @@ def __sub__(self, other):
def __rsub__(self, other):
try:
return pd.TimedeltaIndex(other - np.array(self))
except OverflowError:
except OUT_OF_BOUNDS_TIMEDELTA_ERROR:
raise ValueError(
"The time difference exceeds the range of values "
"that can be expressed at the nanosecond resolution."
Expand Down