Skip to content
forked from pydata/xarray

Commit

Permalink
Rescale datetime for interp() too.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Aug 20, 2018
1 parent 1f1ec52 commit 9ac15ef
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions xarray/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 9ac15ef

Please sign in to comment.