-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Code Sample, a copy-pastable example if possible
This code doesn't work anymore on master.
a = xr.DataArray(np.arange(21).reshape(3, 7),
dims=['x', 'time'],
coords={'x': [1, 2, 3], 'time': pd.date_range('01-01-2001', periods=7, freq='D')})
xi = xr.DataArray(np.linspace(1, 3, 50),
dims=['time'],
coords={'time': pd.date_range('01-01-2001', periods=50, freq='H')})
a.interp(x=xi, time=xi.time)
Problem description
The above code now raises the error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-26-dda3a6d5725b> in <module>
6 dims=['time'],
7 coords={'time': pd.date_range('01-01-2001', periods=50, freq='H')})
----> 8 a.interp(x=xi, time=xi.time)
~/work/python/xarray/xarray/core/dataarray.py in interp(self, coords, method, assume_sorted, kwargs, **coords_kwargs)
1032 ds = self._to_temp_dataset().interp(
1033 coords, method=method, kwargs=kwargs, assume_sorted=assume_sorted,
-> 1034 **coords_kwargs)
1035 return self._from_temp_dataset(ds)
1036
~/work/python/xarray/xarray/core/dataset.py in interp(self, coords, method, assume_sorted, kwargs, **coords_kwargs)
2008 in indexers.items() if k in var.dims}
2009 variables[name] = missing.interp(
-> 2010 var, var_indexers, method, **kwargs)
2011 elif all(d not in indexers for d in var.dims):
2012 # keep unrelated object array
~/work/python/xarray/xarray/core/missing.py in interp(var, indexes_coords, method, **kwargs)
468 new_dims = broadcast_dims + list(destination[0].dims)
469 interped = interp_func(var.transpose(*original_dims).data,
--> 470 x, destination, method, kwargs)
471
472 result = Variable(new_dims, interped, attrs=var.attrs)
~/work/python/xarray/xarray/core/missing.py in interp_func(var, x, new_x, method, kwargs)
535 new_axis=new_axis, drop_axis=drop_axis)
536
--> 537 return _interpnd(var, x, new_x, func, kwargs)
538
539
~/work/python/xarray/xarray/core/missing.py in _interpnd(var, x, new_x, func, kwargs)
558 var = var.transpose(range(-len(x), var.ndim - len(x)))
559 # stack new_x to 1 vector, with reshape
--> 560 xi = np.stack([x1.values.ravel() for x1 in new_x], axis=-1)
561 rslt = func(x, var, xi, **kwargs)
562 # move back the interpolation axes to the last position
~/work/python/xarray/xarray/core/missing.py in <listcomp>(.0)
558 var = var.transpose(range(-len(x), var.ndim - len(x)))
559 # stack new_x to 1 vector, with reshape
--> 560 xi = np.stack([x1.values.ravel() for x1 in new_x], axis=-1)
561 rslt = func(x, var, xi, **kwargs)
562 # move back the interpolation axes to the last position
AttributeError: 'numpy.ndarray' object has no attribute 'values'
I think the issue is this line which returns a numpy array instead of a Variable. This was added in the coarsen
PR (cc @fujiisoup)
Line 636 in d4c4682
return np.where(array.isnull(), np.nan, array.astype(dtype)) |