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

Method _counts

xarray/computation/rolling.py:583–604  ·  view source on GitHub ↗

Number of non-nan entries in each rolling window.

(self, keep_attrs: bool | None)

Source from the content-addressed store, hash-verified

581 return result.where(counts >= self.min_periods)
582
583 def _counts(self, keep_attrs: bool | None) -> DataArray:
584 """Number of non-nan entries in each rolling window."""
585
586 rolling_dim = {
587 d: utils.get_temp_dimname(self.obj.dims, f"_rolling_dim_{d}")
588 for d in self.dim
589 }
590 # We use False as the fill_value instead of np.nan, since boolean
591 # array is faster to be reduced than object array.
592 # The use of skipna==False is also faster since it does not need to
593 # copy the strided array.
594 dim = list(rolling_dim.values())
595 counts = (
596 self.obj.notnull(keep_attrs=keep_attrs)
597 .rolling(
598 dict(zip(self.dim, self.window, strict=True)),
599 center={d: self.center[i] for i, d in enumerate(self.dim)},
600 )
601 .construct(rolling_dim, fill_value=False, keep_attrs=keep_attrs)
602 .sum(dim=dim, skipna=False, keep_attrs=keep_attrs)
603 )
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

Callers 1

reduceMethod · 0.95

Calls 5

valuesMethod · 0.45
sumMethod · 0.45
constructMethod · 0.45
rollingMethod · 0.45
notnullMethod · 0.45

Tested by

no test coverage detected