Number of non-nan entries in each rolling window.
(self, keep_attrs: bool | None)
| 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 |