Reduce the items in this group by applying `func` along some dimension(s). Parameters ---------- func : callable Function which can be called in the form `func(x, axis=axis, **kwargs)` to return the result of collapsing an np.ndarr
(
self,
func: Callable[..., Any],
dim: Dims = None,
*,
axis: int | Sequence[int] | None = None,
keep_attrs: bool | None = None,
keepdims: bool = False,
shortcut: bool = True,
**kwargs: Any,
)
| 1706 | return combined |
| 1707 | |
| 1708 | def reduce( |
| 1709 | self, |
| 1710 | func: Callable[..., Any], |
| 1711 | dim: Dims = None, |
| 1712 | *, |
| 1713 | axis: int | Sequence[int] | None = None, |
| 1714 | keep_attrs: bool | None = None, |
| 1715 | keepdims: bool = False, |
| 1716 | shortcut: bool = True, |
| 1717 | **kwargs: Any, |
| 1718 | ) -> DataArray: |
| 1719 | """Reduce the items in this group by applying `func` along some |
| 1720 | dimension(s). |
| 1721 | |
| 1722 | Parameters |
| 1723 | ---------- |
| 1724 | func : callable |
| 1725 | Function which can be called in the form |
| 1726 | `func(x, axis=axis, **kwargs)` to return the result of collapsing |
| 1727 | an np.ndarray over an integer valued axis. |
| 1728 | dim : "...", str, Iterable of Hashable or None, optional |
| 1729 | Dimension(s) over which to apply `func`. If None, apply over the |
| 1730 | groupby dimension, if "..." apply over all dimensions. |
| 1731 | axis : int or sequence of int, optional |
| 1732 | Axis(es) over which to apply `func`. Only one of the 'dimension' |
| 1733 | and 'axis' arguments can be supplied. If neither are supplied, then |
| 1734 | `func` is calculated over all dimension for each group item. |
| 1735 | keep_attrs : bool, optional |
| 1736 | If True, the datasets's attributes (`attrs`) will be copied from |
| 1737 | the original object to the new one. If False (default), the new |
| 1738 | object will be returned without attributes. |
| 1739 | **kwargs : dict |
| 1740 | Additional keyword arguments passed on to `func`. |
| 1741 | |
| 1742 | Returns |
| 1743 | ------- |
| 1744 | reduced : Array |
| 1745 | Array with summarized data and the indicated dimension(s) |
| 1746 | removed. |
| 1747 | """ |
| 1748 | if self._by_chunked: |
| 1749 | raise ValueError( |
| 1750 | "This method is not supported when lazily grouping by a chunked array. " |
| 1751 | "Try installing the `flox` package if you are using one of the standard " |
| 1752 | "reductions (e.g. `mean`). " |
| 1753 | ) |
| 1754 | if dim is None: |
| 1755 | dim = [self._group_dim] |
| 1756 | |
| 1757 | if keep_attrs is None: |
| 1758 | keep_attrs = _get_keep_attrs(default=True) |
| 1759 | |
| 1760 | def reduce_array(ar: DataArray) -> DataArray: |
| 1761 | return ar.reduce( |
| 1762 | func=func, |
| 1763 | dim=dim, |
| 1764 | axis=axis, |
| 1765 | keep_attrs=keep_attrs, |
nothing calls this directly
no test coverage detected