MCPcopy
hub / github.com/pydata/xarray / _numbagg_reduce

Method _numbagg_reduce

xarray/computation/rolling.py:606–644  ·  view source on GitHub ↗
(self, func, keep_attrs, **kwargs)

Source from the content-addressed store, hash-verified

604 return counts
605
606 def _numbagg_reduce(self, func, keep_attrs, **kwargs):
607 # Some of this is copied from `_bottleneck_reduce`, we could reduce this as part
608 # of a wider refactor.
609
610 axis = self.obj.get_axis_num(self.dim[0])
611
612 padded = self.obj.variable
613 if self.center[0]:
614 if is_duck_dask_array(padded.data):
615 # workaround to make the padded chunk size larger than
616 # self.window - 1
617 shift = -(self.window[0] + 1) // 2
618 offset = (self.window[0] - 1) // 2
619 valid = (slice(None),) * axis + (
620 slice(offset, offset + self.obj.shape[axis]),
621 )
622 else:
623 shift = (-self.window[0] // 2) + 1
624 valid = (slice(None),) * axis + (slice(-shift, None),)
625 padded = padded.pad({self.dim[0]: (0, -shift)}, mode="constant")
626
627 if is_duck_dask_array(padded.data) and False:
628 raise AssertionError("should not be reachable")
629 else:
630 values = func(
631 padded.data,
632 window=self.window[0],
633 min_count=self.min_periods,
634 axis=axis,
635 )
636
637 if self.center[0]:
638 values = values[valid]
639
640 attrs = self.obj.attrs if keep_attrs else {}
641
642 return self.obj.__class__(
643 values, self.obj.coords, attrs=attrs, name=self.obj.name
644 )
645
646 def _bottleneck_reduce(self, func, keep_attrs, **kwargs):
647 # bottleneck doesn't allow min_count to be 0, although it should

Callers 1

_array_reduceMethod · 0.95

Calls 4

is_duck_dask_arrayFunction · 0.90
funcFunction · 0.70
get_axis_numMethod · 0.45
padMethod · 0.45

Tested by

no test coverage detected