From 9ac15ef677c4d21230b7aab40a65c1d7b0530ece Mon Sep 17 00:00:00 2001 From: dcherian Date: Sun, 29 Jul 2018 12:45:36 -0700 Subject: [PATCH] Rescale datetime for interp() too. --- xarray/core/missing.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/xarray/core/missing.py b/xarray/core/missing.py index e7c663db84d..26dd8c5e450 100644 --- a/xarray/core/missing.py +++ b/xarray/core/missing.py @@ -412,15 +412,16 @@ def _floatize_x(x, new_x): x = list(x) new_x = list(new_x) for i in range(len(x)): - if x[i].dtype.kind in 'Mm': - # Scipy casts coordinates to np.float64, which is not accurate - # enough for datetime64 (uses 64bit integer). - # We assume that the most of the bits are used to represent the - # offset (min(x)) and the variation (x - min(x)) can be - # represented by float. - xmin = np.min(x[i]) - x[i] = (x[i] - xmin).astype(np.float64) - new_x[i] = (new_x[i] - xmin).astype(np.float64) + # Scipy casts coordinates to np.float64, which is not accurate + # enough for datetime64 (uses 64bit integer). + # We assume that the most of the bits are used to represent the + # offset (min(x)) and the variation (x - min(x)) can be + # represented by float. + # Let's be defensive and always rescale (x) + xmin = np.min(x[i]) + xstd = np.std(x[i].astype(np.float64)) + x[i] = (x[i] - xmin).astype(np.float64) / xstd + new_x[i] = (new_x[i] - xmin).astype(np.float64) / xstd return x, new_x