diff --git a/xarray/coding/variables.py b/xarray/coding/variables.py index 30fe3384477..eee2858e074 100644 --- a/xarray/coding/variables.py +++ b/xarray/coding/variables.py @@ -9,7 +9,6 @@ import numpy as np import pandas as pd -from xarray.coding import times from xarray.core import dtypes, duck_array_ops, indexing from xarray.core.pycompat import is_duck_dask_array from xarray.core.variable import Variable @@ -286,11 +285,11 @@ def decode(self, variable: Variable, name: T_Name = None): units = attrs.get("units", None) # try to cast to correct dtypes for data and fill_value # GH 7817 - if (( + if ( isinstance(units, str) and "since" in units - and np.issubdtype(data.dtype, np.integer)) or np.issubdtype(data.dtype, np.datetime64) - ): + and np.issubdtype(data.dtype, np.integer) + ) or np.issubdtype(data.dtype, np.datetime64): dtype, decoded_fill_value = data.dtype, np.datetime64("NaT").astype( data.dtype )