Apply reduction function.
(
self, windows, func, boundary="exact", side="left", keep_attrs=None, **kwargs
)
| 2244 | ) |
| 2245 | |
| 2246 | def coarsen( |
| 2247 | self, windows, func, boundary="exact", side="left", keep_attrs=None, **kwargs |
| 2248 | ): |
| 2249 | """ |
| 2250 | Apply reduction function. |
| 2251 | """ |
| 2252 | windows = {k: v for k, v in windows.items() if k in self.dims} |
| 2253 | |
| 2254 | if keep_attrs is None: |
| 2255 | keep_attrs = _get_keep_attrs(default=True) |
| 2256 | |
| 2257 | if keep_attrs: |
| 2258 | _attrs = self.attrs |
| 2259 | else: |
| 2260 | _attrs = None |
| 2261 | |
| 2262 | if not windows: |
| 2263 | return self._replace(attrs=_attrs) |
| 2264 | |
| 2265 | reshaped, axes = self.coarsen_reshape(windows, boundary, side) |
| 2266 | if isinstance(func, str): |
| 2267 | name = func |
| 2268 | func = getattr(duck_array_ops, name, None) |
| 2269 | if func is None: |
| 2270 | raise NameError(f"{name} is not a valid method.") |
| 2271 | |
| 2272 | return self._replace(data=func(reshaped, axis=axes, **kwargs), attrs=_attrs) |
| 2273 | |
| 2274 | def coarsen_reshape(self, windows, boundary, side): |
| 2275 | """ |
nothing calls this directly
no test coverage detected