@@ -191,8 +191,7 @@ def _interpolate(self, kind='linear'):
191
191
from .dataarray import DataArray
192
192
193
193
if isinstance (self ._obj .data , dask_array_type ):
194
- raise NotImplementedError (
195
- 'Resampling by interpolation does not work with dask arrays' )
194
+ raise TypeError ('dask arrays not supported yet in resample.interpolate()' )
196
195
197
196
x = self ._obj [self ._dim ].astype ('float' )
198
197
y = self ._obj .data
@@ -302,42 +301,37 @@ def reduce(self, func, dim=None, keep_attrs=False, **kwargs):
302
301
func , self ._dim , keep_attrs , ** kwargs )
303
302
304
303
def _interpolate (self , kind = 'linear' ):
305
- from .dataarray import DataArray
306
304
from .dataset import Dataset
305
+ from .variable import Variable
307
306
308
- new_x = self ._full_index .values .astype ('float' )
309
-
310
- arrs = {}
307
+ old_times = self ._obj [self ._dim ].astype (float )
308
+ new_times = self ._full_index .values .astype (float )
311
309
312
- # Prepare coordinates by dropping non-dimension coordinates along the
313
- # resampling dimension.
314
- # note: the lower-level Variable API could be used to speed this up
310
+ data_vars = OrderedDict ()
315
311
coords = OrderedDict ()
316
- for k , v in self ._obj .coords .items ():
317
- # is the resampling dimension
318
- if k == self ._dim :
319
- coords [self ._dim ] = self ._full_index
320
- # else, check if resampling dim is in coordinate dimensions
321
- elif self ._dim not in v .dims :
322
- coords [k ] = v
323
312
324
313
# Apply the interpolation to each DataArray in our original Dataset
325
- for var in self ._obj .data_vars :
326
- da = self ._obj [var ].copy ()
327
-
328
- x = da [self ._dim ].astype ('float' )
329
- y = da .values
330
- axis = da .get_axis_num (self ._dim )
331
-
332
- f = interp1d (x , y , kind = kind , axis = axis , bounds_error = True ,
333
- assume_sorted = True )
334
-
335
- # Construct new DataArray
336
- arrs [var ] = DataArray (f (new_x ), dims = da .dims , name = da .name ,
337
- attrs = da .attrs )
338
-
339
- # Merge into a new Dataset to return
340
- return Dataset (arrs , coords = coords )
314
+ for name , variable in self ._obj .variables .items ():
315
+ if name in self ._obj .coords :
316
+ if name == self ._dim :
317
+ coords [self ._dim ] = self ._full_index
318
+ elif self ._dim not in variable .dims :
319
+ coords [name ] = variable
320
+ else :
321
+ if isinstance (variable .data , dask_array_type ):
322
+ raise TypeError ('dask arrays not supported yet in '
323
+ 'resample.interpolate()' )
324
+
325
+ axis = variable .get_axis_num (self ._dim )
326
+
327
+ f = interp1d (old_times , variable .data , kind = kind ,
328
+ axis = axis , bounds_error = True ,
329
+ assume_sorted = True )
330
+ interpolated = Variable (variable .dims , f (new_times ))
331
+
332
+ data_vars [name ] = interpolated
333
+
334
+ return Dataset (data_vars , coords )
341
335
342
336
343
337
ops .inject_reduce_methods (DatasetResample )
0 commit comments