Skip to content
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
14 changes: 8 additions & 6 deletions xarray/coding/cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import warnings
from datetime import timedelta
from distutils.version import LooseVersion
from typing import Tuple, Type

import numpy as np
import pandas as pd
Expand All @@ -59,10 +60,11 @@
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
OUT_OF_BOUNDS_TIMEDELTA_ERRORS: Tuple[Type[Exception], ...]
try:
OUT_OF_BOUNDS_TIMEDELTA_ERRORS = (pd.errors.OutOfBoundsTimedelta, OverflowError)
except AttributeError:
OUT_OF_BOUNDS_TIMEDELTA_ERRORS = (OverflowError,)


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