MCPcopy Create free account
hub / github.com/pydata/xarray / reduce

Method reduce

xarray/core/groupby.py:1872–1938  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

1870 return combined
1871
1872 def reduce(
1873 self,
1874 func: Callable[..., Any],
1875 dim: Dims = None,
1876 *,
1877 axis: int | Sequence[int] | None = None,
1878 keep_attrs: bool | None = None,
1879 keepdims: bool = False,
1880 shortcut: bool = True,
1881 **kwargs: Any,
1882 ) -> Dataset:
1883 """Reduce the items in this group by applying `func` along some
1884 dimension(s).
1885
1886 Parameters
1887 ----------
1888 func : callable
1889 Function which can be called in the form
1890 `func(x, axis=axis, **kwargs)` to return the result of collapsing
1891 an np.ndarray over an integer valued axis.
1892 dim : ..., str, Iterable of Hashable or None, optional
1893 Dimension(s) over which to apply `func`. By default apply over the
1894 groupby dimension, with "..." apply over all dimensions.
1895 axis : int or sequence of int, optional
1896 Axis(es) over which to apply `func`. Only one of the 'dimension'
1897 and 'axis' arguments can be supplied. If neither are supplied, then
1898 `func` is calculated over all dimension for each group item.
1899 keep_attrs : bool, optional
1900 If True, the datasets's attributes (`attrs`) will be copied from
1901 the original object to the new one. If False (default), the new
1902 object will be returned without attributes.
1903 **kwargs : dict
1904 Additional keyword arguments passed on to `func`.
1905
1906 Returns
1907 -------
1908 reduced : Dataset
1909 Array with summarized data and the indicated dimension(s)
1910 removed.
1911 """
1912
1913 if self._by_chunked:
1914 raise ValueError(
1915 "This method is not supported when lazily grouping by a chunked array. "
1916 "Try installing the `flox` package if you are using one of the standard "
1917 "reductions (e.g. `mean`). "
1918 )
1919
1920 if dim is None:
1921 dim = [self._group_dim]
1922
1923 if keep_attrs is None:
1924 keep_attrs = _get_keep_attrs(default=True)
1925
1926 def reduce_dataset(ds: Dataset) -> Dataset:
1927 return ds.reduce(
1928 func=func,
1929 dim=dim,

Callers

nothing calls this directly

Calls 3

mapMethod · 0.95
_get_keep_attrsFunction · 0.90
check_reduce_dimsFunction · 0.85

Tested by

no test coverage detected