diff --git a/xarray/coding/variables.py b/xarray/coding/variables.py index eee2858e074..71bab010a5b 100644 --- a/xarray/coding/variables.py +++ b/xarray/coding/variables.py @@ -241,7 +241,7 @@ def encode(self, variable: Variable, name: T_Name = None): if isinstance(units, str) and "since" in units: encoded_dtype = encoding.pop("dtype") if encoded_dtype is not None and encoded_dtype != data.dtype: - data = np.asarray(data, dtype=encoded_dtype) + data = duck_array_ops.astype(data, encoded_dtype) if fv_exists: # Ensure _FillValue is cast to same dtype as data's