def _counts(self, keep_attrs: bool | None) -> DataArray:
        """Number of non-nan entries in each rolling window."""

        rolling_dim = {
            d: utils.get_temp_dimname(self.obj.dims, f"_rolling_dim_{d}")
            for d in self.dim
        }
        # We use False as the fill_value instead of np.nan, since boolean
        # array is faster to be reduced than object array.
        # The use of skipna==False is also faster since it does not need to
        # copy the strided array.
        dim = list(rolling_dim.values())
        counts = (
            self.obj.notnull(keep_attrs=keep_attrs)
            .rolling(
                dict(zip(self.dim, self.window, strict=True)),
                center={d: self.center[i] for i, d in enumerate(self.dim)},
            )
            .construct(rolling_dim, fill_value=False, keep_attrs=keep_attrs)
            .sum(dim=dim, skipna=False, keep_attrs=keep_attrs)
        )
        return counts
Number of non-nan entries in each rolling window.
xarray/computation/rolling.py