From 398f1b660233402fdf7e631f0ee5f863cae564a2 Mon Sep 17 00:00:00 2001 From: dcherian Date: Fri, 20 May 2022 08:47:56 -0600 Subject: [PATCH] Backward compatibility dask --- xarray/core/duck_array_ops.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index a8d7476f1ab..033c238b959 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -431,7 +431,14 @@ def datetime_to_numeric(array, offset=None, datetime_unit=None, dtype=float): # Compute timedelta object. # For np.datetime64, this can silently yield garbage due to overflow. # One option is to enforce 1970-01-01 as the universal offset. - array = array - offset + + # This map_blocks call is for backwards compatibility. + # dask == 2021.04.1 does not support subtracting object arrays + # which is required for cftime + if is_duck_dask_array(array): + array = array.map_blocks(lambda a, b: a - b, offset) + else: + array = array - offset # Scalar is converted to 0d-array if not hasattr(array, "dtype"):