From 45df347268158809b9b74315efbe2447b4a09251 Mon Sep 17 00:00:00 2001 From: Ewan Short Date: Fri, 12 Dec 2025 20:55:04 +1100 Subject: [PATCH 1/4] implement default dims in open_zarr GH8749 --- doc/whats-new.rst | 2 + xarray/backends/zarr.py | 119 ++- xarray/core/_aggregations.py | 1545 ++-------------------------- xarray/namedarray/_aggregations.py | 99 +- xarray/tests/test_backends.py | 90 +- 5 files changed, 247 insertions(+), 1608 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 7e3badc7143..97911ddabd8 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -29,6 +29,8 @@ Bug Fixes - Ensure that ``keep_attrs='drop'`` and ``keep_attrs=False`` remove attrs from result, even when there is only one xarray object given to ``apply_ufunc`` (:issue:`10982` :pull:`10997`). By `Julia Signell `_. +- Improve the robustness of ``open_zarr`` by attempting to load datasets with default dimension names if dimension name metadata is missing (:issue:`8749`). + By `Ewan Short `_. Documentation ~~~~~~~~~~~~~ diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index fe004c212b6..fda77002423 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -4,6 +4,7 @@ import json import os import struct +import warnings from collections.abc import Hashable, Iterable, Mapping from typing import TYPE_CHECKING, Any, Literal, Self, cast @@ -355,56 +356,96 @@ def _determine_zarr_chunks(enc_chunks, var_chunks, ndim, name): def _get_zarr_dims_and_attrs(zarr_obj, dimension_key, try_nczarr): - # Zarr V3 explicitly stores the dimension names in the metadata + def get_default_dims(zarr_obj): + # Helper function to create default dimension names in cases where these don't + # exist in the metadata. Note the dimension_names parameter is optional in + # zarr version 3 + # https://zarr-specs.readthedocs.io/en/latest/v3/core/index.html#dimension-names + # Dimension name metadata is also optional in zarr version 2 + # https://zarr-specs.readthedocs.io/en/latest/v2/v2.0.html#attributes + + return tuple(f"dim_{n}" for n in range(len(zarr_obj.shape))) + + def get_nczarr_dims(zarr_obj): + # Helper function to extract dimension names from NCZarr metadata in .zarray + # https://docs.unidata.ucar.edu/netcdf/NUG/nczarr_head.html + zarray_path = os.path.join(zarr_obj.path, ".zarray") + # Check available zarr module version (not zarr version of zarr_obj) version + if _zarr_v3(): + import asyncio + + zarray_str = asyncio.run(zarr_obj.store.get(zarray_path)).to_bytes() + else: + zarray_str = zarr_obj.store.get(zarray_path) + zarray = json.loads(zarray_str) + try: + # NCZarr uses Fully Qualified Names + dimensions = [ + os.path.basename(dim) for dim in zarray["_NCZARR_ARRAY"]["dimrefs"] + ] + except KeyError: + dimensions = get_default_dims(zarr_obj) + return dimensions + + # Zarr V3 specifies an optional dimension_names array metadata parameter, so + # check if this exists try: - # if this exists, we are looking at a Zarr V3 array - # convert None to empty tuple + # If dimension_names exists, we are looking at a Zarr V3 array + # Convert None to empty tuple dimensions = zarr_obj.metadata.dimension_names or () except AttributeError: - # continue to old code path + # Continue to old code path pass else: + # Check number of dimensions in metadata match shape of array. + # If not, use defaults attributes = dict(zarr_obj.attrs) if len(zarr_obj.shape) != len(dimensions): - raise KeyError( - "Zarr object is missing the `dimension_names` metadata which is " - "required for xarray to determine variable dimensions." - ) + if not dimensions: + message = "Missing metadata dimension names." + else: + message = ( + f"Metadata dimension names {dimensions} inconsistent with array " + f"shape {zarr_obj.shape}." + ) + message += " Attempting with defaults." + warnings.warn(message, UserWarning, stacklevel=2) + dimensions = get_default_dims(zarr_obj) return dimensions, attributes - # Zarr arrays do not have dimensions. To get around this problem, we add - # an attribute that specifies the dimension. We have to hide this attribute - # when we send the attributes to the user. - # zarr_obj can be either a zarr group or zarr array + # Zarr 2 arrays do not necessarily have dimension names. + # https://zarr-specs.readthedocs.io/en/latest/v2/v2.0.html#attributes + # To get around this problem, we add an attribute that specifies the + # dimension. We have to hide this attribute when we send the + # attributes to the user. Note zarr_obj can be either a zarr group + # or zarr array + + # First try to read dimension names using old xarray-zarr convention. + # dimension_key typically _ARRAY_DIMENSIONS try: # Xarray-Zarr dimensions = zarr_obj.attrs[dimension_key] - except KeyError as e: + except KeyError: + warnings.warn( + "Failed to read dimension names from xarray zarr metadata.", + UserWarning, + stacklevel=2, + ) if not try_nczarr: - raise KeyError( - f"Zarr object is missing the attribute `{dimension_key}`, which is " - "required for xarray to determine variable dimensions." - ) from e - - # NCZarr defines dimensions through metadata in .zarray - zarray_path = os.path.join(zarr_obj.path, ".zarray") - if _zarr_v3(): - import asyncio - - zarray_str = asyncio.run(zarr_obj.store.get(zarray_path)).to_bytes() + # Skip straight to using default dimensions + dimensions = get_default_dims(zarr_obj) else: - zarray_str = zarr_obj.store.get(zarray_path) - zarray = json.loads(zarray_str) - try: - # NCZarr uses Fully Qualified Names - dimensions = [ - os.path.basename(dim) for dim in zarray["_NCZARR_ARRAY"]["dimrefs"] - ] - except KeyError as e: - raise KeyError( - f"Zarr object is missing the attribute `{dimension_key}` and the NCZarr metadata, " - "which are required for xarray to determine variable dimensions." - ) from e + # Try to read dimension names using NCZarr convention + try: + dimensions = get_nczarr_dims(zarr_obj) + except Exception: + # Fallback to default dimension names + warnings.warn( + "Failed to read dimension names from netcdf zarr metadata.", + UserWarning, + stacklevel=2, + ) + dimensions = get_default_dims(zarr_obj) nc_attrs = [attr for attr in zarr_obj.attrs if attr.lower().startswith("_nc")] attributes = HiddenKeyDict(zarr_obj.attrs, [dimension_key] + nc_attrs) @@ -1424,8 +1465,10 @@ def open_zarr( """Load and decode a dataset from a Zarr store. The `store` object should be a valid store for a Zarr group. `store` - variables must contain dimension metadata encoded in the - `_ARRAY_DIMENSIONS` attribute or must have NCZarr format. + variables should contain dimension metadata encoded in the + `_ARRAY_DIMENSIONS` attribute for zarr 2, the `dimension_names` attribute for zarr + 3, or the `dim_refs` parameter for NCZarr. If dimension name metadata is missing, + `open_zarr` will attempt to build the dataset using default dimension names. Parameters ---------- diff --git a/xarray/core/_aggregations.py b/xarray/core/_aggregations.py index adc064840de..1746d2516a1 100644 --- a/xarray/core/_aggregations.py +++ b/xarray/core/_aggregations.py @@ -88,21 +88,8 @@ def count( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.count() - - Group: / - Dimensions: () - Data variables: - foo int64 8B 5 """ return self.reduce( duck_array_ops.count, @@ -171,21 +158,8 @@ def all( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.all() - - Group: / - Dimensions: () - Data variables: - foo bool 1B False """ return self.reduce( duck_array_ops.array_all, @@ -254,21 +228,8 @@ def any( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.any() - - Group: / - Dimensions: () - Data variables: - foo bool 1B True """ return self.reduce( duck_array_ops.array_any, @@ -338,30 +299,12 @@ def max( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.max() - - Group: / - Dimensions: () - Data variables: - foo float64 8B 3.0 Use ``skipna`` to control whether NaNs are ignored. >>> dt.max(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan """ return self.reduce( duck_array_ops.max, @@ -432,30 +375,12 @@ def min( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.min() - - Group: / - Dimensions: () - Data variables: - foo float64 8B 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> dt.min(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan """ return self.reduce( duck_array_ops.min, @@ -513,7 +438,7 @@ def mean( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -530,30 +455,12 @@ def mean( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.mean() - - Group: / - Dimensions: () - Data variables: - foo float64 8B 1.6 Use ``skipna`` to control whether NaNs are ignored. >>> dt.mean(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan """ return self.reduce( duck_array_ops.mean, @@ -618,7 +525,7 @@ def prod( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -635,39 +542,16 @@ def prod( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.prod() - - Group: / - Dimensions: () - Data variables: - foo float64 8B 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> dt.prod(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan Specify ``min_count`` for finer control over when NaNs are ignored. >>> dt.prod(skipna=True, min_count=2) - - Group: / - Dimensions: () - Data variables: - foo float64 8B 0.0 """ return self.reduce( duck_array_ops.prod, @@ -733,7 +617,7 @@ def sum( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -750,39 +634,16 @@ def sum( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.sum() - - Group: / - Dimensions: () - Data variables: - foo float64 8B 8.0 Use ``skipna`` to control whether NaNs are ignored. >>> dt.sum(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan Specify ``min_count`` for finer control over when NaNs are ignored. >>> dt.sum(skipna=True, min_count=2) - - Group: / - Dimensions: () - Data variables: - foo float64 8B 8.0 """ return self.reduce( duck_array_ops.sum, @@ -845,7 +706,7 @@ def std( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -862,39 +723,16 @@ def std( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.std() - - Group: / - Dimensions: () - Data variables: - foo float64 8B 1.02 Use ``skipna`` to control whether NaNs are ignored. >>> dt.std(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan Specify ``ddof=1`` for an unbiased estimate. >>> dt.std(skipna=True, ddof=1) - - Group: / - Dimensions: () - Data variables: - foo float64 8B 1.14 """ return self.reduce( duck_array_ops.std, @@ -957,7 +795,7 @@ def var( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -974,39 +812,16 @@ def var( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.var() - - Group: / - Dimensions: () - Data variables: - foo float64 8B 1.04 Use ``skipna`` to control whether NaNs are ignored. >>> dt.var(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan Specify ``ddof=1`` for an unbiased estimate. >>> dt.var(skipna=True, ddof=1) - - Group: / - Dimensions: () - Data variables: - foo float64 8B 1.3 """ return self.reduce( duck_array_ops.var, @@ -1065,7 +880,7 @@ def median( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -1082,30 +897,12 @@ def median( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.median() - - Group: / - Dimensions: () - Data variables: - foo float64 8B 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> dt.median(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan """ return self.reduce( duck_array_ops.median, @@ -1164,7 +961,7 @@ def cumsum( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -1185,32 +982,12 @@ def cumsum( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.cumsum() - - Group: / - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - foo (time) float64 48B 1.0 3.0 6.0 6.0 8.0 8.0 Use ``skipna`` to control whether NaNs are ignored. >>> dt.cumsum(skipna=False) - - Group: / - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - foo (time) float64 48B 1.0 3.0 6.0 6.0 8.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -1269,7 +1046,7 @@ def cumprod( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -1290,32 +1067,12 @@ def cumprod( ... ), ... ) >>> dt - - Group: / - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> dt.cumprod() - - Group: / - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - foo (time) float64 48B 1.0 2.0 6.0 0.0 0.0 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> dt.cumprod(skipna=False) - - Group: / - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - foo (time) float64 48B 1.0 2.0 6.0 0.0 0.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -1392,19 +1149,8 @@ def count( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.count() - Size: 8B - Dimensions: () - Data variables: - da int64 8B 5 """ return self.reduce( duck_array_ops.count, @@ -1464,19 +1210,8 @@ def all( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 78B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.all() - Size: 1B - Dimensions: () - Data variables: - da bool 1B False """ return self.reduce( duck_array_ops.array_all, @@ -1536,19 +1271,8 @@ def any( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 78B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.any() - Size: 1B - Dimensions: () - Data variables: - da bool 1B True """ return self.reduce( duck_array_ops.array_any, @@ -1614,27 +1338,12 @@ def max( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.max() - Size: 8B - Dimensions: () - Data variables: - da float64 8B 3.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.max(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan """ return self.reduce( duck_array_ops.max, @@ -1701,27 +1410,12 @@ def min( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.min() - Size: 8B - Dimensions: () - Data variables: - da float64 8B 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.min(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan """ return self.reduce( duck_array_ops.min, @@ -1776,6 +1470,10 @@ def mean( :ref:`agg` User guide on reduction or aggregation operations. + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + Examples -------- >>> da = xr.DataArray( @@ -1788,27 +1486,12 @@ def mean( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.mean() - Size: 8B - Dimensions: () - Data variables: - da float64 8B 1.6 Use ``skipna`` to control whether NaNs are ignored. >>> ds.mean(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan """ return self.reduce( duck_array_ops.mean, @@ -1872,7 +1555,7 @@ def prod( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -1886,35 +1569,16 @@ def prod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.prod() - Size: 8B - Dimensions: () - Data variables: - da float64 8B 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.prod(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.prod(skipna=True, min_count=2) - Size: 8B - Dimensions: () - Data variables: - da float64 8B 0.0 """ return self.reduce( duck_array_ops.prod, @@ -1979,7 +1643,7 @@ def sum( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -1993,35 +1657,16 @@ def sum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.sum() - Size: 8B - Dimensions: () - Data variables: - da float64 8B 8.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.sum(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.sum(skipna=True, min_count=2) - Size: 8B - Dimensions: () - Data variables: - da float64 8B 8.0 """ return self.reduce( duck_array_ops.sum, @@ -2083,7 +1728,7 @@ def std( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -2097,35 +1742,16 @@ def std( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.std() - Size: 8B - Dimensions: () - Data variables: - da float64 8B 1.02 Use ``skipna`` to control whether NaNs are ignored. >>> ds.std(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan Specify ``ddof=1`` for an unbiased estimate. >>> ds.std(skipna=True, ddof=1) - Size: 8B - Dimensions: () - Data variables: - da float64 8B 1.14 """ return self.reduce( duck_array_ops.std, @@ -2187,7 +1813,7 @@ def var( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -2201,35 +1827,16 @@ def var( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.var() - Size: 8B - Dimensions: () - Data variables: - da float64 8B 1.04 Use ``skipna`` to control whether NaNs are ignored. >>> ds.var(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan Specify ``ddof=1`` for an unbiased estimate. >>> ds.var(skipna=True, ddof=1) - Size: 8B - Dimensions: () - Data variables: - da float64 8B 1.3 """ return self.reduce( duck_array_ops.var, @@ -2287,7 +1894,7 @@ def median( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -2301,27 +1908,12 @@ def median( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.median() - Size: 8B - Dimensions: () - Data variables: - da float64 8B 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.median(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan """ return self.reduce( duck_array_ops.median, @@ -2379,7 +1971,7 @@ def cumsum( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -2397,29 +1989,12 @@ def cumsum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.cumsum() - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 3.0 6.0 6.0 8.0 8.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.cumsum(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 3.0 6.0 6.0 8.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -2477,7 +2052,7 @@ def cumprod( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -2495,29 +2070,12 @@ def cumprod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.cumprod() - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 6.0 0.0 0.0 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.cumprod(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 6.0 0.0 0.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -2593,15 +2151,8 @@ def count( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.count() - Size: 8B - array(5) """ return self.reduce( duck_array_ops.count, @@ -2659,15 +2210,8 @@ def all( ... ), ... ) >>> da - Size: 6B - array([ True, True, True, True, True, False]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.all() - Size: 1B - array(False) """ return self.reduce( duck_array_ops.array_all, @@ -2725,15 +2269,8 @@ def any( ... ), ... ) >>> da - Size: 6B - array([ True, True, True, True, True, False]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.any() - Size: 1B - array(True) """ return self.reduce( duck_array_ops.array_any, @@ -2797,21 +2334,12 @@ def max( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.max() - Size: 8B - array(3.) Use ``skipna`` to control whether NaNs are ignored. >>> da.max(skipna=False) - Size: 8B - array(nan) """ return self.reduce( duck_array_ops.max, @@ -2876,21 +2404,12 @@ def min( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.min() - Size: 8B - array(0.) Use ``skipna`` to control whether NaNs are ignored. >>> da.min(skipna=False) - Size: 8B - array(nan) """ return self.reduce( duck_array_ops.min, @@ -2944,6 +2463,10 @@ def mean( :ref:`agg` User guide on reduction or aggregation operations. + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + Examples -------- >>> da = xr.DataArray( @@ -2955,21 +2478,12 @@ def mean( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.mean() - Size: 8B - array(1.6) Use ``skipna`` to control whether NaNs are ignored. >>> da.mean(skipna=False) - Size: 8B - array(nan) """ return self.reduce( duck_array_ops.mean, @@ -3032,7 +2546,7 @@ def prod( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -3045,27 +2559,16 @@ def prod( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.prod() - Size: 8B - array(0.) Use ``skipna`` to control whether NaNs are ignored. >>> da.prod(skipna=False) - Size: 8B - array(nan) Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.prod(skipna=True, min_count=2) - Size: 8B - array(0.) """ return self.reduce( duck_array_ops.prod, @@ -3129,7 +2632,7 @@ def sum( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -3142,27 +2645,16 @@ def sum( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.sum() - Size: 8B - array(8.) Use ``skipna`` to control whether NaNs are ignored. >>> da.sum(skipna=False) - Size: 8B - array(nan) Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.sum(skipna=True, min_count=2) - Size: 8B - array(8.) """ return self.reduce( duck_array_ops.sum, @@ -3223,7 +2715,7 @@ def std( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -3236,27 +2728,16 @@ def std( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.std() - Size: 8B - array(1.0198039) Use ``skipna`` to control whether NaNs are ignored. >>> da.std(skipna=False) - Size: 8B - array(nan) Specify ``ddof=1`` for an unbiased estimate. >>> da.std(skipna=True, ddof=1) - Size: 8B - array(1.14017543) """ return self.reduce( duck_array_ops.std, @@ -3317,7 +2798,7 @@ def var( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -3330,27 +2811,16 @@ def var( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.var() - Size: 8B - array(1.04) Use ``skipna`` to control whether NaNs are ignored. >>> da.var(skipna=False) - Size: 8B - array(nan) Specify ``ddof=1`` for an unbiased estimate. >>> da.var(skipna=True, ddof=1) - Size: 8B - array(1.3) """ return self.reduce( duck_array_ops.var, @@ -3407,7 +2877,7 @@ def median( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -3420,21 +2890,12 @@ def median( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.median() - Size: 8B - array(2.) Use ``skipna`` to control whether NaNs are ignored. >>> da.median(skipna=False) - Size: 8B - array(nan) """ return self.reduce( duck_array_ops.median, @@ -3491,7 +2952,7 @@ def cumsum( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -3508,27 +2969,12 @@ def cumsum( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.cumsum() - Size: 48B - array([1., 3., 6., 6., 8., 8.]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.cumsum(skipna=False) - Size: 48B - array([ 1., 3., 6., 6., 8., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.cumprod() - Size: 48B - array([1., 2., 6., 0., 0., 0.]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.cumprod(skipna=False) - Size: 48B - array([ 1., 2., 6., 0., 0., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").count() - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) int64 24B 1 2 2 """ if ( flox_available @@ -3809,21 +3227,8 @@ def all( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 78B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").all() - Size: 27B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) bool 3B False True True """ if ( flox_available @@ -3905,21 +3310,8 @@ def any( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 78B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").any() - Size: 27B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) bool 3B True True True """ if ( flox_available @@ -4007,31 +3399,12 @@ def max( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").max() - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B 1.0 2.0 3.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").max(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 2.0 3.0 """ if ( flox_available @@ -4121,31 +3494,12 @@ def min( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").min() - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B 1.0 2.0 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").min(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 2.0 0.0 """ if ( flox_available @@ -4223,6 +3577,8 @@ def mean( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + Examples -------- >>> da = xr.DataArray( @@ -4235,31 +3591,12 @@ def mean( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").mean() - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B 1.0 2.0 1.5 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").mean(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 2.0 1.5 """ if ( flox_available @@ -4344,7 +3681,7 @@ def prod( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -4358,41 +3695,16 @@ def prod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").prod() - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B 1.0 4.0 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").prod(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 4.0 0.0 Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.groupby("labels").prod(skipna=True, min_count=2) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 4.0 0.0 """ if ( flox_available @@ -4479,7 +3791,7 @@ def sum( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -4493,41 +3805,16 @@ def sum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").sum() - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B 1.0 4.0 3.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").sum(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 4.0 3.0 Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.groupby("labels").sum(skipna=True, min_count=2) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 4.0 3.0 """ if ( flox_available @@ -4611,7 +3898,7 @@ def std( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -4625,41 +3912,16 @@ def std( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").std() - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B 0.0 0.0 1.5 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").std(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 0.0 1.5 Specify ``ddof=1`` for an unbiased estimate. >>> ds.groupby("labels").std(skipna=True, ddof=1) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 0.0 2.121 """ if ( flox_available @@ -4743,7 +4005,7 @@ def var( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -4757,41 +4019,16 @@ def var( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").var() - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B 0.0 0.0 2.25 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").var(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 0.0 2.25 Specify ``ddof=1`` for an unbiased estimate. >>> ds.groupby("labels").var(skipna=True, ddof=1) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 0.0 4.5 """ if ( flox_available @@ -4871,7 +4108,7 @@ def median( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -4885,31 +4122,12 @@ def median( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").median() - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B 1.0 2.0 1.5 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").median(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 2.0 1.5 """ return self.reduce( duck_array_ops.median, @@ -4973,7 +4191,7 @@ def cumsum( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -4991,29 +4209,12 @@ def cumsum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").cumsum() - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 3.0 3.0 4.0 1.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").cumsum(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 3.0 3.0 4.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -5077,7 +4278,7 @@ def cumprod( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -5095,29 +4296,12 @@ def cumprod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").cumprod() - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 3.0 0.0 4.0 1.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").cumprod(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 3.0 0.0 4.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -5209,21 +4393,8 @@ def count( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").count() - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) int64 24B 1 3 1 """ if ( flox_available @@ -5305,21 +4476,8 @@ def all( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 78B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").all() - Size: 27B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) bool 3B True True False """ if ( flox_available @@ -5401,21 +4559,8 @@ def any( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 78B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").any() - Size: 27B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) bool 3B True True True """ if ( flox_available @@ -5503,31 +4648,12 @@ def max( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").max() - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 3.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").max(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 3.0 nan """ if ( flox_available @@ -5617,31 +4743,12 @@ def min( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").min() - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 0.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").min(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 0.0 nan """ if ( flox_available @@ -5719,6 +4826,8 @@ def mean( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + Examples -------- >>> da = xr.DataArray( @@ -5731,31 +4840,12 @@ def mean( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").mean() - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 1.667 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").mean(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 1.667 nan """ if ( flox_available @@ -5840,7 +4930,7 @@ def prod( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -5854,41 +4944,16 @@ def prod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").prod() - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 0.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").prod(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 0.0 nan Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.resample(time="3ME").prod(skipna=True, min_count=2) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B nan 0.0 nan """ if ( flox_available @@ -5975,7 +5040,7 @@ def sum( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -5989,41 +5054,16 @@ def sum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").sum() - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 5.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").sum(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 5.0 nan Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.resample(time="3ME").sum(skipna=True, min_count=2) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B nan 5.0 nan """ if ( flox_available @@ -6107,7 +5147,7 @@ def std( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -6121,41 +5161,16 @@ def std( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").std() - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 0.0 1.247 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").std(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 0.0 1.247 nan Specify ``ddof=1`` for an unbiased estimate. >>> ds.resample(time="3ME").std(skipna=True, ddof=1) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B nan 1.528 nan """ if ( flox_available @@ -6239,7 +5254,7 @@ def var( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -6253,41 +5268,16 @@ def var( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").var() - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 0.0 1.556 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").var(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 0.0 1.556 nan Specify ``ddof=1`` for an unbiased estimate. >>> ds.resample(time="3ME").var(skipna=True, ddof=1) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B nan 2.333 nan """ if ( flox_available @@ -6367,7 +5357,7 @@ def median( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -6381,31 +5371,12 @@ def median( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").median() - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 2.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").median(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 2.0 nan """ return self.reduce( duck_array_ops.median, @@ -6469,7 +5440,7 @@ def cumsum( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -6487,29 +5458,12 @@ def cumsum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").cumsum() - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 5.0 5.0 2.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").cumsum(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 5.0 5.0 2.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -6573,7 +5527,7 @@ def cumprod( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -6591,29 +5545,12 @@ def cumprod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - Size: 120B - Dimensions: (time: 6) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").cumprod() - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 6.0 0.0 2.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").cumprod(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 6.0 0.0 2.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -6704,17 +5641,8 @@ def count( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").count() - Size: 24B - array([1, 2, 2]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6793,17 +5721,8 @@ def all( ... ), ... ) >>> da - Size: 6B - array([ True, True, True, True, True, False]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").all() - Size: 3B - array([False, True, True]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6882,17 +5801,8 @@ def any( ... ), ... ) >>> da - Size: 6B - array([ True, True, True, True, True, False]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").any() - Size: 3B - array([ True, True, True]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6977,25 +5887,12 @@ def max( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").max() - Size: 24B - array([1., 2., 3.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").max(skipna=False) - Size: 24B - array([nan, 2., 3.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7082,25 +5979,12 @@ def min( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").min() - Size: 24B - array([1., 2., 0.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").min(skipna=False) - Size: 24B - array([nan, 2., 0.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7176,6 +6060,8 @@ def mean( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + Examples -------- >>> da = xr.DataArray( @@ -7187,25 +6073,12 @@ def mean( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").mean() - Size: 24B - array([1. , 2. , 1.5]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").mean(skipna=False) - Size: 24B - array([nan, 2. , 1.5]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7288,7 +6161,7 @@ def prod( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -7301,33 +6174,16 @@ def prod( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").prod() - Size: 24B - array([1., 4., 0.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").prod(skipna=False) - Size: 24B - array([nan, 4., 0.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.groupby("labels").prod(skipna=True, min_count=2) - Size: 24B - array([nan, 4., 0.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7412,7 +6268,7 @@ def sum( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -7425,33 +6281,16 @@ def sum( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").sum() - Size: 24B - array([1., 4., 3.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").sum(skipna=False) - Size: 24B - array([nan, 4., 3.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.groupby("labels").sum(skipna=True, min_count=2) - Size: 24B - array([nan, 4., 3.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7533,7 +6372,7 @@ def std( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -7546,33 +6385,16 @@ def std( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").std() - Size: 24B - array([0. , 0. , 1.5]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").std(skipna=False) - Size: 24B - array([nan, 0. , 1.5]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Specify ``ddof=1`` for an unbiased estimate. >>> da.groupby("labels").std(skipna=True, ddof=1) - Size: 24B - array([ nan, 0. , 2.12132034]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7654,7 +6476,7 @@ def var( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -7667,33 +6489,16 @@ def var( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").var() - Size: 24B - array([0. , 0. , 2.25]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").var(skipna=False) - Size: 24B - array([ nan, 0. , 2.25]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Specify ``ddof=1`` for an unbiased estimate. >>> da.groupby("labels").var(skipna=True, ddof=1) - Size: 24B - array([nan, 0. , 4.5]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7771,7 +6576,7 @@ def median( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -7784,25 +6589,12 @@ def median( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").median() - Size: 24B - array([1. , 2. , 1.5]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").median(skipna=False) - Size: 24B - array([nan, 2. , 1.5]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' """ return self.reduce( duck_array_ops.median, @@ -7865,7 +6657,7 @@ def cumsum( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -7882,27 +6674,12 @@ def cumsum( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").cumsum() - Size: 48B - array([1., 2., 3., 3., 4., 1.]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").cumsum(skipna=False) - Size: 48B - array([ 1., 2., 3., 3., 4., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -7982,27 +6759,12 @@ def cumprod( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").cumprod() - Size: 48B - array([1., 2., 3., 0., 4., 1.]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").cumprod(skipna=False) - Size: 48B - array([ 1., 2., 3., 0., 4., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").count() - Size: 24B - array([1, 3, 1]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8181,17 +6934,8 @@ def all( ... ), ... ) >>> da - Size: 6B - array([ True, True, True, True, True, False]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").all() - Size: 3B - array([ True, True, False]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8270,17 +7014,8 @@ def any( ... ), ... ) >>> da - Size: 6B - array([ True, True, True, True, True, False]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").any() - Size: 3B - array([ True, True, True]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8365,25 +7100,12 @@ def max( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").max() - Size: 24B - array([1., 3., 2.]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").max(skipna=False) - Size: 24B - array([ 1., 3., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8470,25 +7192,12 @@ def min( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").min() - Size: 24B - array([1., 0., 2.]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").min(skipna=False) - Size: 24B - array([ 1., 0., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8564,6 +7273,8 @@ def mean( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + Examples -------- >>> da = xr.DataArray( @@ -8575,25 +7286,12 @@ def mean( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").mean() - Size: 24B - array([1. , 1.66666667, 2. ]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").mean(skipna=False) - Size: 24B - array([1. , 1.66666667, nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8676,7 +7374,7 @@ def prod( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -8689,33 +7387,16 @@ def prod( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").prod() - Size: 24B - array([1., 0., 2.]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").prod(skipna=False) - Size: 24B - array([ 1., 0., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.resample(time="3ME").prod(skipna=True, min_count=2) - Size: 24B - array([nan, 0., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8800,7 +7481,7 @@ def sum( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -8813,33 +7494,16 @@ def sum( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").sum() - Size: 24B - array([1., 5., 2.]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").sum(skipna=False) - Size: 24B - array([ 1., 5., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.resample(time="3ME").sum(skipna=True, min_count=2) - Size: 24B - array([nan, 5., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8921,7 +7585,7 @@ def std( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -8934,33 +7598,16 @@ def std( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").std() - Size: 24B - array([0. , 1.24721913, 0. ]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").std(skipna=False) - Size: 24B - array([0. , 1.24721913, nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Specify ``ddof=1`` for an unbiased estimate. >>> da.resample(time="3ME").std(skipna=True, ddof=1) - Size: 24B - array([ nan, 1.52752523, nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -9042,7 +7689,7 @@ def var( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -9055,33 +7702,16 @@ def var( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").var() - Size: 24B - array([0. , 1.55555556, 0. ]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").var(skipna=False) - Size: 24B - array([0. , 1.55555556, nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Specify ``ddof=1`` for an unbiased estimate. >>> da.resample(time="3ME").var(skipna=True, ddof=1) - Size: 24B - array([ nan, 2.33333333, nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -9159,7 +7789,7 @@ def median( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- @@ -9172,25 +7802,12 @@ def median( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").median() - Size: 24B - array([1., 2., 2.]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").median(skipna=False) - Size: 24B - array([ 1., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ return self.reduce( duck_array_ops.median, @@ -9253,7 +7870,7 @@ def cumsum( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -9270,27 +7887,12 @@ def cumsum( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").cumsum() - Size: 48B - array([1., 2., 5., 5., 2., 2.]) - Coordinates: - labels (time) >> da.resample(time="3ME").cumsum(skipna=False) - Size: 48B - array([ 1., 2., 5., 5., 2., nan]) - Coordinates: - labels (time) `_ for more. - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -9370,27 +7972,12 @@ def cumprod( ... ), ... ) >>> da - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").cumprod() - Size: 48B - array([1., 2., 6., 0., 2., 2.]) - Coordinates: - labels (time) >> da.resample(time="3ME").cumprod(skipna=False) - Size: 48B - array([ 1., 2., 6., 0., 2., nan]) - Coordinates: - labels (time) >> from xarray.namedarray.core import NamedArray >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) >>> na - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) >>> na.count() - Size: 8B - array(5) """ return self.reduce( duck_array_ops.count, @@ -116,12 +111,8 @@ def all( ... "x", np.array([True, True, True, True, True, False], dtype=bool) ... ) >>> na - Size: 6B - array([ True, True, True, True, True, False]) >>> na.all() - Size: 1B - array(False) """ return self.reduce( duck_array_ops.array_all, @@ -169,12 +160,8 @@ def any( ... "x", np.array([True, True, True, True, True, False], dtype=bool) ... ) >>> na - Size: 6B - array([ True, True, True, True, True, False]) >>> na.any() - Size: 1B - array(True) """ return self.reduce( duck_array_ops.array_any, @@ -227,18 +214,12 @@ def max( >>> from xarray.namedarray.core import NamedArray >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) >>> na - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) >>> na.max() - Size: 8B - array(3.) Use ``skipna`` to control whether NaNs are ignored. >>> na.max(skipna=False) - Size: 8B - array(nan) """ return self.reduce( duck_array_ops.max, @@ -292,18 +273,12 @@ def min( >>> from xarray.namedarray.core import NamedArray >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) >>> na - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) >>> na.min() - Size: 8B - array(0.) Use ``skipna`` to control whether NaNs are ignored. >>> na.min(skipna=False) - Size: 8B - array(nan) """ return self.reduce( duck_array_ops.min, @@ -352,23 +327,21 @@ def mean( :ref:`agg` User guide on reduction or aggregation operations. + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + Examples -------- >>> from xarray.namedarray.core import NamedArray >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) >>> na - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) >>> na.mean() - Size: 8B - array(1.6) Use ``skipna`` to control whether NaNs are ignored. >>> na.mean(skipna=False) - Size: 8B - array(nan) """ return self.reduce( duck_array_ops.mean, @@ -426,31 +399,23 @@ def prod( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- >>> from xarray.namedarray.core import NamedArray >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) >>> na - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) >>> na.prod() - Size: 8B - array(0.) Use ``skipna`` to control whether NaNs are ignored. >>> na.prod(skipna=False) - Size: 8B - array(nan) Specify ``min_count`` for finer control over when NaNs are ignored. >>> na.prod(skipna=True, min_count=2) - Size: 8B - array(0.) """ return self.reduce( duck_array_ops.prod, @@ -509,31 +474,23 @@ def sum( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- >>> from xarray.namedarray.core import NamedArray >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) >>> na - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) >>> na.sum() - Size: 8B - array(8.) Use ``skipna`` to control whether NaNs are ignored. >>> na.sum(skipna=False) - Size: 8B - array(nan) Specify ``min_count`` for finer control over when NaNs are ignored. >>> na.sum(skipna=True, min_count=2) - Size: 8B - array(8.) """ return self.reduce( duck_array_ops.sum, @@ -589,31 +546,23 @@ def std( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- >>> from xarray.namedarray.core import NamedArray >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) >>> na - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) >>> na.std() - Size: 8B - array(1.0198039) Use ``skipna`` to control whether NaNs are ignored. >>> na.std(skipna=False) - Size: 8B - array(nan) Specify ``ddof=1`` for an unbiased estimate. >>> na.std(skipna=True, ddof=1) - Size: 8B - array(1.14017543) """ return self.reduce( duck_array_ops.std, @@ -669,31 +618,23 @@ def var( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- >>> from xarray.namedarray.core import NamedArray >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) >>> na - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) >>> na.var() - Size: 8B - array(1.04) Use ``skipna`` to control whether NaNs are ignored. >>> na.var(skipna=False) - Size: 8B - array(nan) Specify ``ddof=1`` for an unbiased estimate. >>> na.var(skipna=True, ddof=1) - Size: 8B - array(1.3) """ return self.reduce( duck_array_ops.var, @@ -745,25 +686,19 @@ def median( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Examples -------- >>> from xarray.namedarray.core import NamedArray >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) >>> na - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) >>> na.median() - Size: 8B - array(2.) Use ``skipna`` to control whether NaNs are ignored. >>> na.median(skipna=False) - Size: 8B - array(nan) """ return self.reduce( duck_array_ops.median, @@ -815,7 +750,7 @@ def cumsum( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -826,18 +761,12 @@ def cumsum( >>> from xarray.namedarray.core import NamedArray >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) >>> na - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) >>> na.cumsum() - Size: 48B - array([1., 3., 6., 6., 8., 8.]) Use ``skipna`` to control whether NaNs are ignored. >>> na.cumsum(skipna=False) - Size: 48B - array([ 1., 3., 6., 6., 8., nan]) """ return self.reduce( duck_array_ops.cumsum, @@ -889,7 +818,7 @@ def cumprod( Notes ----- - Non-numeric variables will be removed prior to reducing. + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) and better supported. ``cumsum`` and ``cumprod`` may be deprecated @@ -900,18 +829,12 @@ def cumprod( >>> from xarray.namedarray.core import NamedArray >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) >>> na - Size: 48B - array([ 1., 2., 3., 0., 2., nan]) >>> na.cumprod() - Size: 48B - array([1., 2., 6., 0., 0., 0.]) Use ``skipna`` to control whether NaNs are ignored. >>> na.cumprod(skipna=False) - Size: 48B - array([ 1., 2., 6., 0., 0., nan]) """ return self.reduce( duck_array_ops.cumprod, diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 5aab153117d..8135191c421 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -2,8 +2,10 @@ import asyncio import contextlib +import glob import gzip import itertools +import json import math import os.path import pickle @@ -3022,7 +3024,7 @@ def test_hidden_zarr_keys(self) -> None: del attrs[self.DIMENSION_KEY] zarr_group["var2"].attrs.put(attrs) - with pytest.raises(KeyError): + with pytest.warns(UserWarning, match="Failed to read dimension names"): with xr.decode_cf(store): pass @@ -4371,6 +4373,88 @@ def create_zarr_target(self): with create_tmp_file(suffix=".zarr") as tmp: yield tmp + # Helper functions for stripping dimension metadata from zarr stores + def _strip_zarr_3(self, ds_path, stripped_ds_path): + """Create a copy of a zarr 3 with dimension_names metadata removed.""" + shutil.copytree(ds_path, stripped_ds_path, dirs_exist_ok=True) + # Get all the zarr.json metadata files. + metadata_files = glob.glob(f"{stripped_ds_path}/**/zarr.json", recursive=True) + # Iterate through and remove all "dimension_names" entries + for file in metadata_files: + with open(file) as f: + metadata = json.load(f) + metadata.pop("dimension_names", None) + con_metadata = metadata.get("consolidated_metadata", None) + if con_metadata: + for k in con_metadata["metadata"].keys(): + con_metadata["metadata"][k].pop("dimension_names", None) + + with open(file, "w") as f: + json.dump(metadata, f, indent=2) + + def _strip_zarr_2(self, ds_path, stripped_ds_path): + """Create a copy of a zarr 2 with _ARRAY_DIMENSIONS metadata removed.""" + # Get all the .zattrs files. Note .zattrs are optional in zarr 2, but xarray uses + # them to store dimension name metadata. + # https://zarr-specs.readthedocs.io/en/latest/v2/v2.0.html#attributes + shutil.copytree(ds_path, stripped_ds_path, dirs_exist_ok=True) + zattrs_files = glob.glob(f"{stripped_ds_path}/**/.zattrs", recursive=True) + # Iterate through and remove all "_ARRAY_DIMENSIONS" entries + for file in zattrs_files: + with open(file) as f: + metadata = json.load(f) + metadata.pop("_ARRAY_DIMENSIONS", None) + with open(file, "w") as f: + json.dump(metadata, f, indent=2) + zmetadata_file = Path(stripped_ds_path) / ".zmetadata" + if zmetadata_file.exists(): + with open(zmetadata_file) as f: + metadata = json.load(f) + for k in metadata["metadata"].keys(): + metadata["metadata"][k].pop("_ARRAY_DIMENSIONS", None) + with open(zmetadata_file, "w") as f: + json.dump(metadata, f, indent=2) + + @pytest.mark.parametrize("consolidated", [True, False]) + def test_default_dims(self, consolidated): + zarr_format = zarr.config.get("default_zarr_format") + print(zarr_format) + # Create example data that can be read without dimension name metadata + da_a = xr.DataArray(np.arange(3 * 18).reshape(3, 18), dims=["label", "z"]) + da_b = xr.DataArray(np.arange(3), dims="label") + ds_1 = xr.Dataset({"a": da_a, "b": da_b}) + + # Specify what we expect to get when dimension name metadata is missing + expected = ds_1.rename_dims({"label": "dim_0", "z": "dim_1"}) + + def get_stripped_ds(ds, consolidated, zarr_format): + with self.create_zarr_target() as ds_target: + kwargs = {"consolidated": consolidated, "zarr_format": zarr_format} + ds.to_zarr(ds_target, **kwargs) + with self.create_zarr_target() as stripped_ds_target: + if zarr_format == 3: + self._strip_zarr_3(ds_target, stripped_ds_target) + else: + self._strip_zarr_2(ds_target, stripped_ds_target) + with pytest.warns(UserWarning, match="dimension names"): + return xr.open_zarr(stripped_ds_target, **kwargs).compute() + + stripped_ds_1 = get_stripped_ds(ds_1, consolidated, zarr_format) + assert_equal(stripped_ds_1, expected) + + # Create example data that cannot be read without dimension name metadata + da_c = xr.DataArray(np.arange(18), dims="z") + ds_2 = xr.Dataset({"a": da_a, "c": da_c}) + + with pytest.raises(ValueError, match="conflicting sizes for dimension"): + get_stripped_ds(ds_2, consolidated, zarr_format) + + # Failure to open_zarr on ds_2 reflects the failure to create an xarray Dataset without + # proper labeling of dimensions; variables must have consistent dimensions reading + # shape from left to right. + with pytest.raises(AlignmentError, match="cannot reindex or align along"): + xr.Dataset({"a": xr.DataArray(da_a.values), "c": xr.DataArray(da_c.values)}) + @requires_zarr class TestZarrWriteEmpty(TestZarrDirectoryStore): @@ -7587,13 +7671,13 @@ def test_zarr_create_default_indexes(tmp_path, create_default_indexes) -> None: @requires_zarr @pytest.mark.usefixtures("default_zarr_format") -def test_raises_key_error_on_invalid_zarr_store(tmp_path): +def test_user_warning_on_invalid_zarr_store(tmp_path): root = zarr.open_group(tmp_path / "tmp.zarr") if Version(zarr.__version__) < Version("3.0.0"): root.create_dataset("bar", shape=(3, 5), dtype=np.float32) else: root.create_array("bar", shape=(3, 5), dtype=np.float32) - with pytest.raises(KeyError, match=r"xarray to determine variable dimensions"): + with pytest.warns(UserWarning, match=r"dimension names"): xr.open_zarr(tmp_path / "tmp.zarr", consolidated=False) From 98faf7ed4ef1d7fa1bd790ec8e97c518b2c22261 Mon Sep 17 00:00:00 2001 From: Ewan Short Date: Fri, 12 Dec 2025 20:55:44 +1100 Subject: [PATCH 2/4] fix precommit --- xarray/core/_aggregations.py | 12812 +++++++++++++++------------ xarray/namedarray/_aggregations.py | 1304 +-- 2 files changed, 7963 insertions(+), 6153 deletions(-) diff --git a/xarray/core/_aggregations.py b/xarray/core/_aggregations.py index 1746d2516a1..479c7e4e56d 100644 --- a/xarray/core/_aggregations.py +++ b/xarray/core/_aggregations.py @@ -42,54 +42,72 @@ def count( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - Dataset.count - DataArray.count - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.count() + Reduce this DataTree's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + Dataset.count + DataArray.count + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.count() + + Group: / + Dimensions: () + Data variables: + foo int64 8B 5 """ return self.reduce( duck_array_ops.count, @@ -107,59 +125,78 @@ def all( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - Dataset.all - DataArray.all - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=( - ... "time", - ... np.array([True, True, True, True, True, False], dtype=bool), - ... ) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.all() + Reduce this DataTree's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + Dataset.all + DataArray.all + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=( + ... "time", + ... np.array( + ... [True, True, True, True, True, False], + ... dtype=bool, + ... ), + ... ) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.all() + + Group: / + Dimensions: () + Data variables: + foo bool 1B False """ return self.reduce( duck_array_ops.array_all, @@ -177,59 +214,78 @@ def any( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - Dataset.any - DataArray.any - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=( - ... "time", - ... np.array([True, True, True, True, True, False], dtype=bool), - ... ) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.any() + Reduce this DataTree's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + Dataset.any + DataArray.any + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=( + ... "time", + ... np.array( + ... [True, True, True, True, True, False], + ... dtype=bool, + ... ), + ... ) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.any() + + Group: / + Dimensions: () + Data variables: + foo bool 1B True """ return self.reduce( duck_array_ops.array_any, @@ -248,63 +304,86 @@ def max( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - Dataset.max - DataArray.max - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.max() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> dt.max(skipna=False) + Reduce this DataTree's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + Dataset.max + DataArray.max + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.max() + + Group: / + Dimensions: () + Data variables: + foo float64 8B 3.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> dt.max(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan """ return self.reduce( duck_array_ops.max, @@ -324,63 +403,86 @@ def min( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - Dataset.min - DataArray.min - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.min() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> dt.min(skipna=False) + Reduce this DataTree's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + Dataset.min + DataArray.min + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.min() + + Group: / + Dimensions: () + Data variables: + foo float64 8B 0.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> dt.min(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan """ return self.reduce( duck_array_ops.min, @@ -400,67 +502,90 @@ def mean( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - Dataset.mean - DataArray.mean - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.mean() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> dt.mean(skipna=False) + Reduce this DataTree's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + Dataset.mean + DataArray.mean + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.mean() + + Group: / + Dimensions: () + Data variables: + foo float64 8B 1.6 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> dt.mean(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan """ return self.reduce( duck_array_ops.mean, @@ -481,77 +606,105 @@ def prod( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - Dataset.prod - DataArray.prod - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.prod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> dt.prod(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> dt.prod(skipna=True, min_count=2) + Reduce this DataTree's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + Dataset.prod + DataArray.prod + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.prod() + + Group: / + Dimensions: () + Data variables: + foo float64 8B 0.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> dt.prod(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> dt.prod(skipna=True, min_count=2) + + Group: / + Dimensions: () + Data variables: + foo float64 8B 0.0 """ return self.reduce( duck_array_ops.prod, @@ -573,77 +726,105 @@ def sum( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - Dataset.sum - DataArray.sum - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.sum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> dt.sum(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> dt.sum(skipna=True, min_count=2) + Reduce this DataTree's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + Dataset.sum + DataArray.sum + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.sum() + + Group: / + Dimensions: () + Data variables: + foo float64 8B 8.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> dt.sum(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> dt.sum(skipna=True, min_count=2) + + Group: / + Dimensions: () + Data variables: + foo float64 8B 8.0 """ return self.reduce( duck_array_ops.sum, @@ -665,74 +846,102 @@ def std( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - Dataset.std - DataArray.std - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.std() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> dt.std(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> dt.std(skipna=True, ddof=1) + Reduce this DataTree's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + Dataset.std + DataArray.std + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.std() + + Group: / + Dimensions: () + Data variables: + foo float64 8B 1.02 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> dt.std(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan + + Specify ``ddof=1`` for an unbiased estimate. + + >>> dt.std(skipna=True, ddof=1) + + Group: / + Dimensions: () + Data variables: + foo float64 8B 1.14 """ return self.reduce( duck_array_ops.std, @@ -754,74 +963,102 @@ def var( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - Dataset.var - DataArray.var - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.var() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> dt.var(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> dt.var(skipna=True, ddof=1) + Reduce this DataTree's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + Dataset.var + DataArray.var + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.var() + + Group: / + Dimensions: () + Data variables: + foo float64 8B 1.04 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> dt.var(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan + + Specify ``ddof=1`` for an unbiased estimate. + + >>> dt.var(skipna=True, ddof=1) + + Group: / + Dimensions: () + Data variables: + foo float64 8B 1.3 """ return self.reduce( duck_array_ops.var, @@ -842,67 +1079,90 @@ def median( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - Dataset.median - DataArray.median - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.median() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> dt.median(skipna=False) + Reduce this DataTree's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + Dataset.median + DataArray.median + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.median() + + Group: / + Dimensions: () + Data variables: + foo float64 8B 2.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> dt.median(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan """ return self.reduce( duck_array_ops.median, @@ -922,72 +1182,97 @@ def cumsum( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - Dataset.cumsum - DataArray.cumsum - DataTree.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.cumsum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> dt.cumsum(skipna=False) + Reduce this DataTree's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + Dataset.cumsum + DataArray.cumsum + DataTree.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.cumsum() + + Group: / + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + foo (time) float64 48B 1.0 3.0 6.0 6.0 8.0 8.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> dt.cumsum(skipna=False) + + Group: / + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + foo (time) float64 48B 1.0 3.0 6.0 6.0 8.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -1007,72 +1292,97 @@ def cumprod( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - Dataset.cumprod - DataArray.cumprod - DataTree.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ), - ... ) - >>> dt - - >>> dt.cumprod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> dt.cumprod(skipna=False) + Reduce this DataTree's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + Dataset.cumprod + DataArray.cumprod + DataTree.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=( + ... "time", + ... np.array(["a", "b", "c", "c", "b", "a"]), + ... ), + ... ), + ... ), + ... ) + >>> dt + + Group: / + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> dt.cumprod() + + Group: / + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + foo (time) float64 48B 1.0 2.0 6.0 0.0 0.0 0.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> dt.cumprod(skipna=False) + + Group: / + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + foo (time) float64 48B 1.0 2.0 6.0 0.0 0.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -1107,50 +1417,64 @@ def count( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - DataArray.count - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.count() + Reduce this Dataset's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + DataArray.count + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.count() + Size: 8B + Dimensions: () + Data variables: + da int64 8B 5 """ return self.reduce( duck_array_ops.count, @@ -1168,50 +1492,64 @@ def all( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - DataArray.all - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.all() + Reduce this Dataset's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + DataArray.all + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 78B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.all() + Size: 1B + Dimensions: () + Data variables: + da bool 1B False """ return self.reduce( duck_array_ops.array_all, @@ -1229,50 +1567,64 @@ def any( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - DataArray.any - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.any() + Reduce this Dataset's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + DataArray.any + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 78B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.any() + Size: 1B + Dimensions: () + Data variables: + da bool 1B True """ return self.reduce( duck_array_ops.array_any, @@ -1291,59 +1643,77 @@ def max( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - DataArray.max - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.max() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.max(skipna=False) + Reduce this Dataset's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + DataArray.max + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.max() + Size: 8B + Dimensions: () + Data variables: + da float64 8B 3.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.max(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan """ return self.reduce( duck_array_ops.max, @@ -1363,59 +1733,77 @@ def min( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - DataArray.min - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.min() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.min(skipna=False) + Reduce this Dataset's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + DataArray.min + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.min() + Size: 8B + Dimensions: () + Data variables: + da float64 8B 0.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.min(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan """ return self.reduce( duck_array_ops.min, @@ -1435,63 +1823,81 @@ def mean( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - DataArray.mean - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.mean() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.mean(skipna=False) + Reduce this Dataset's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + DataArray.mean + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.mean() + Size: 8B + Dimensions: () + Data variables: + da float64 8B 1.6 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.mean(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan """ return self.reduce( duck_array_ops.mean, @@ -1512,73 +1918,95 @@ def prod( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - DataArray.prod - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.prod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.prod(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> ds.prod(skipna=True, min_count=2) + Reduce this Dataset's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + DataArray.prod + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.prod() + Size: 8B + Dimensions: () + Data variables: + da float64 8B 0.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.prod(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> ds.prod(skipna=True, min_count=2) + Size: 8B + Dimensions: () + Data variables: + da float64 8B 0.0 """ return self.reduce( duck_array_ops.prod, @@ -1600,73 +2028,95 @@ def sum( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - DataArray.sum - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.sum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.sum(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> ds.sum(skipna=True, min_count=2) + Reduce this Dataset's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + DataArray.sum + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.sum() + Size: 8B + Dimensions: () + Data variables: + da float64 8B 8.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.sum(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> ds.sum(skipna=True, min_count=2) + Size: 8B + Dimensions: () + Data variables: + da float64 8B 8.0 """ return self.reduce( duck_array_ops.sum, @@ -1688,70 +2138,92 @@ def std( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - DataArray.std - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.std() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.std(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> ds.std(skipna=True, ddof=1) + Reduce this Dataset's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + DataArray.std + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.std() + Size: 8B + Dimensions: () + Data variables: + da float64 8B 1.02 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.std(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan + + Specify ``ddof=1`` for an unbiased estimate. + + >>> ds.std(skipna=True, ddof=1) + Size: 8B + Dimensions: () + Data variables: + da float64 8B 1.14 """ return self.reduce( duck_array_ops.std, @@ -1773,70 +2245,92 @@ def var( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - DataArray.var - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.var() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.var(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> ds.var(skipna=True, ddof=1) + Reduce this Dataset's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + DataArray.var + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.var() + Size: 8B + Dimensions: () + Data variables: + da float64 8B 1.04 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.var(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan + + Specify ``ddof=1`` for an unbiased estimate. + + >>> ds.var(skipna=True, ddof=1) + Size: 8B + Dimensions: () + Data variables: + da float64 8B 1.3 """ return self.reduce( duck_array_ops.var, @@ -1857,63 +2351,81 @@ def median( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - DataArray.median - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.median() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.median(skipna=False) + Reduce this Dataset's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + DataArray.median + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.median() + Size: 8B + Dimensions: () + Data variables: + da float64 8B 2.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.median(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan """ return self.reduce( duck_array_ops.median, @@ -1933,68 +2445,88 @@ def cumsum( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - DataArray.cumsum - Dataset.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.cumsum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.cumsum(skipna=False) + Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + DataArray.cumsum + Dataset.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.cumsum() + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 3.0 6.0 6.0 8.0 8.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.cumsum(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 3.0 6.0 6.0 8.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -2014,68 +2546,88 @@ def cumprod( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - DataArray.cumprod - Dataset.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.cumprod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.cumprod(skipna=False) + Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + DataArray.cumprod + Dataset.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.cumprod() + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 6.0 0.0 0.0 0.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.cumprod(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 6.0 0.0 0.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -2110,49 +2662,59 @@ def count( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - Dataset.count - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.count() + Reduce this DataArray's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + Dataset.count + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.count() + Size: 8B + array(5) """ return self.reduce( duck_array_ops.count, @@ -2169,49 +2731,59 @@ def all( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - Dataset.all - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.all() + Reduce this DataArray's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + Dataset.all + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 6B + array([ True, True, True, True, True, False]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.all() + Size: 1B + array(False) """ return self.reduce( duck_array_ops.array_all, @@ -2228,49 +2800,59 @@ def any( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - Dataset.any - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.any() + Reduce this DataArray's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + Dataset.any + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 6B + array([ True, True, True, True, True, False]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.any() + Size: 1B + array(True) """ return self.reduce( duck_array_ops.array_any, @@ -2288,58 +2870,70 @@ def max( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - Dataset.max - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.max() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.max(skipna=False) + Reduce this DataArray's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + Dataset.max + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.max() + Size: 8B + array(3.) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.max(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.max, @@ -2358,58 +2952,70 @@ def min( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - Dataset.min - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.min() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.min(skipna=False) + Reduce this DataArray's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + Dataset.min + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.min() + Size: 8B + array(0.) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.min(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.min, @@ -2428,62 +3034,74 @@ def mean( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - Dataset.mean - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.mean() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.mean(skipna=False) + Reduce this DataArray's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + Dataset.mean + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.mean() + Size: 8B + array(1.6) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.mean(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.mean, @@ -2503,72 +3121,86 @@ def prod( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - Dataset.prod - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.prod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.prod(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> da.prod(skipna=True, min_count=2) + Reduce this DataArray's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + Dataset.prod + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.prod() + Size: 8B + array(0.) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.prod(skipna=False) + Size: 8B + array(nan) + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> da.prod(skipna=True, min_count=2) + Size: 8B + array(0.) """ return self.reduce( duck_array_ops.prod, @@ -2589,72 +3221,86 @@ def sum( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - Dataset.sum - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.sum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.sum(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> da.sum(skipna=True, min_count=2) + Reduce this DataArray's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + Dataset.sum + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.sum() + Size: 8B + array(8.) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.sum(skipna=False) + Size: 8B + array(nan) + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> da.sum(skipna=True, min_count=2) + Size: 8B + array(8.) """ return self.reduce( duck_array_ops.sum, @@ -2675,69 +3321,83 @@ def std( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - Dataset.std - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.std() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.std(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> da.std(skipna=True, ddof=1) + Reduce this DataArray's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + Dataset.std + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.std() + Size: 8B + array(1.0198039) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.std(skipna=False) + Size: 8B + array(nan) + + Specify ``ddof=1`` for an unbiased estimate. + + >>> da.std(skipna=True, ddof=1) + Size: 8B + array(1.14017543) """ return self.reduce( duck_array_ops.std, @@ -2758,69 +3418,83 @@ def var( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - Dataset.var - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.var() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.var(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> da.var(skipna=True, ddof=1) + Reduce this DataArray's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + Dataset.var + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.var() + Size: 8B + array(1.04) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.var(skipna=False) + Size: 8B + array(nan) + + Specify ``ddof=1`` for an unbiased estimate. + + >>> da.var(skipna=True, ddof=1) + Size: 8B + array(1.3) """ return self.reduce( duck_array_ops.var, @@ -2840,62 +3514,74 @@ def median( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - Dataset.median - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.median() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.median(skipna=False) + Reduce this DataArray's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + Dataset.median + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.median() + Size: 8B + array(2.) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.median(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.median, @@ -2914,67 +3600,85 @@ def cumsum( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - Dataset.cumsum - DataArray.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.cumsum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.cumsum(skipna=False) + Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + Dataset.cumsum + DataArray.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.cumsum() + Size: 48B + array([1., 3., 6., 6., 8., 8.]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.cumsum(skipna=False) + Size: 48B + array([ 1., 3., 6., 6., 8., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) Self: """ - Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - Dataset.cumprod - DataArray.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.cumprod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.cumprod(skipna=False) + Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + Dataset.cumprod + DataArray.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.cumprod() + Size: 48B + array([1., 2., 6., 0., 0., 0.]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.cumprod(skipna=False) + Size: 48B + array([ 1., 2., 6., 0., 0., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) Dataset: """ - Reduce this Dataset's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - Dataset.count - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").count() + Reduce this Dataset's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + Dataset.count + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").count() + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) int64 24B 1 2 2 """ if ( flox_available @@ -3177,58 +3915,74 @@ def all( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - Dataset.all - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").all() + Reduce this Dataset's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + Dataset.all + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 78B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").all() + Size: 27B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) bool 3B False True True """ if ( flox_available @@ -3260,58 +4014,74 @@ def any( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - Dataset.any - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").any() + Reduce this Dataset's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + Dataset.any + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 78B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").any() + Size: 27B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) bool 3B True True True """ if ( flox_available @@ -3344,67 +4114,89 @@ def max( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - Dataset.max - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").max() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.groupby("labels").max(skipna=False) + Reduce this Dataset's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + Dataset.max + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").max() + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B 1.0 2.0 3.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.groupby("labels").max(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 2.0 3.0 """ if ( flox_available @@ -3439,67 +4231,89 @@ def min( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - Dataset.min - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").min() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.groupby("labels").min(skipna=False) + Reduce this Dataset's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + Dataset.min + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").min() + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B 1.0 2.0 0.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.groupby("labels").min(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 2.0 0.0 """ if ( flox_available @@ -3534,69 +4348,91 @@ def mean( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - Dataset.mean - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").mean() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.groupby("labels").mean(skipna=False) + Reduce this Dataset's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + Dataset.mean + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").mean() + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B 1.0 2.0 1.5 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.groupby("labels").mean(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 2.0 1.5 """ if ( flox_available @@ -3632,79 +4468,107 @@ def prod( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - Dataset.prod - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").prod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.groupby("labels").prod(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> ds.groupby("labels").prod(skipna=True, min_count=2) + Reduce this Dataset's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + Dataset.prod + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").prod() + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B 1.0 4.0 0.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.groupby("labels").prod(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 4.0 0.0 + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> ds.groupby("labels").prod(skipna=True, min_count=2) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 4.0 0.0 """ if ( flox_available @@ -3742,79 +4606,107 @@ def sum( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - Dataset.sum - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").sum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.groupby("labels").sum(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> ds.groupby("labels").sum(skipna=True, min_count=2) + Reduce this Dataset's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + Dataset.sum + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").sum() + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B 1.0 4.0 3.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.groupby("labels").sum(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 4.0 3.0 + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> ds.groupby("labels").sum(skipna=True, min_count=2) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 4.0 3.0 """ if ( flox_available @@ -3852,76 +4744,104 @@ def std( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - Dataset.std - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").std() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.groupby("labels").std(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> ds.groupby("labels").std(skipna=True, ddof=1) + Reduce this Dataset's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + Dataset.std + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").std() + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B 0.0 0.0 1.5 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.groupby("labels").std(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 0.0 1.5 + + Specify ``ddof=1`` for an unbiased estimate. + + >>> ds.groupby("labels").std(skipna=True, ddof=1) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 0.0 2.121 """ if ( flox_available @@ -3959,76 +4879,104 @@ def var( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - Dataset.var - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").var() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.groupby("labels").var(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> ds.groupby("labels").var(skipna=True, ddof=1) + Reduce this Dataset's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + Dataset.var + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").var() + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B 0.0 0.0 2.25 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.groupby("labels").var(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 0.0 2.25 + + Specify ``ddof=1`` for an unbiased estimate. + + >>> ds.groupby("labels").var(skipna=True, ddof=1) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 0.0 4.5 """ if ( flox_available @@ -4065,69 +5013,91 @@ def median( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - Dataset.median - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").median() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.groupby("labels").median(skipna=False) + Reduce this Dataset's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + Dataset.median + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").median() + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B 1.0 2.0 1.5 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.groupby("labels").median(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 2.0 1.5 """ return self.reduce( duck_array_ops.median, @@ -4147,74 +5117,94 @@ def cumsum( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - Dataset.cumsum - Dataset.cumulative - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").cumsum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.groupby("labels").cumsum(skipna=False) + Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + Dataset.cumsum + Dataset.cumulative + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").cumsum() + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 3.0 3.0 4.0 1.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.groupby("labels").cumsum(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 3.0 3.0 4.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -4234,74 +5224,94 @@ def cumprod( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - Dataset.cumprod - Dataset.cumulative - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.groupby("labels").cumprod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.groupby("labels").cumprod(skipna=False) + Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + Dataset.cumprod + Dataset.cumulative + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.groupby("labels").cumprod() + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 3.0 0.0 4.0 1.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.groupby("labels").cumprod(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 3.0 0.0 4.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -4343,58 +5353,74 @@ def count( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - Dataset.count - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").count() + Reduce this Dataset's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + Dataset.count + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").count() + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) int64 24B 1 3 1 """ if ( flox_available @@ -4426,58 +5452,74 @@ def all( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - Dataset.all - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").all() + Reduce this Dataset's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + Dataset.all + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 78B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").all() + Size: 27B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) bool 3B True True False """ if ( flox_available @@ -4509,58 +5551,74 @@ def any( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - Dataset.any - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").any() + Reduce this Dataset's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + Dataset.any + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 78B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").any() + Size: 27B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) bool 3B True True True """ if ( flox_available @@ -4593,67 +5651,89 @@ def max( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - Dataset.max - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").max() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.resample(time="3ME").max(skipna=False) + Reduce this Dataset's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + Dataset.max + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").max() + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 3.0 2.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.resample(time="3ME").max(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 3.0 nan """ if ( flox_available @@ -4688,67 +5768,89 @@ def min( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - Dataset.min - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").min() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.resample(time="3ME").min(skipna=False) + Reduce this Dataset's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + Dataset.min + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").min() + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 0.0 2.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.resample(time="3ME").min(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 0.0 nan """ if ( flox_available @@ -4783,69 +5885,91 @@ def mean( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - Dataset.mean - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").mean() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.resample(time="3ME").mean(skipna=False) + Reduce this Dataset's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + Dataset.mean + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").mean() + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 1.667 2.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.resample(time="3ME").mean(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 1.667 nan """ if ( flox_available @@ -4881,79 +6005,107 @@ def prod( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - Dataset.prod - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").prod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.resample(time="3ME").prod(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> ds.resample(time="3ME").prod(skipna=True, min_count=2) + Reduce this Dataset's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + Dataset.prod + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").prod() + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 0.0 2.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.resample(time="3ME").prod(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 0.0 nan + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> ds.resample(time="3ME").prod(skipna=True, min_count=2) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B nan 0.0 nan """ if ( flox_available @@ -4991,79 +6143,107 @@ def sum( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - Dataset.sum - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").sum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.resample(time="3ME").sum(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> ds.resample(time="3ME").sum(skipna=True, min_count=2) + Reduce this Dataset's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + Dataset.sum + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").sum() + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 5.0 2.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.resample(time="3ME").sum(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 5.0 nan + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> ds.resample(time="3ME").sum(skipna=True, min_count=2) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B nan 5.0 nan """ if ( flox_available @@ -5101,76 +6281,104 @@ def std( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - Dataset.std - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").std() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.resample(time="3ME").std(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> ds.resample(time="3ME").std(skipna=True, ddof=1) + Reduce this Dataset's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + Dataset.std + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").std() + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 0.0 1.247 0.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.resample(time="3ME").std(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 0.0 1.247 nan + + Specify ``ddof=1`` for an unbiased estimate. + + >>> ds.resample(time="3ME").std(skipna=True, ddof=1) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B nan 1.528 nan """ if ( flox_available @@ -5208,76 +6416,104 @@ def var( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - Dataset.var - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").var() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.resample(time="3ME").var(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> ds.resample(time="3ME").var(skipna=True, ddof=1) + Reduce this Dataset's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + Dataset.var + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").var() + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 0.0 1.556 0.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.resample(time="3ME").var(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 0.0 1.556 nan + + Specify ``ddof=1`` for an unbiased estimate. + + >>> ds.resample(time="3ME").var(skipna=True, ddof=1) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B nan 2.333 nan """ if ( flox_available @@ -5314,69 +6550,91 @@ def median( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - Dataset.median - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").median() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.resample(time="3ME").median(skipna=False) + Reduce this Dataset's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + Dataset.median + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").median() + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 2.0 2.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.resample(time="3ME").median(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 2.0 nan """ return self.reduce( duck_array_ops.median, @@ -5396,74 +6654,94 @@ def cumsum( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - Dataset.cumsum - Dataset.cumulative - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").cumsum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.resample(time="3ME").cumsum(skipna=False) + Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + Dataset.cumsum + Dataset.cumulative + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").cumsum() + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 5.0 5.0 2.0 2.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.resample(time="3ME").cumsum(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 5.0 5.0 2.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -5483,74 +6761,94 @@ def cumprod( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - Dataset.cumprod - Dataset.cumulative - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds - - >>> ds.resample(time="3ME").cumprod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> ds.resample(time="3ME").cumprod(skipna=False) + Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + Dataset.cumprod + Dataset.cumulative + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds + Size: 120B + Dimensions: (time: 6) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> ds.resample(time="3ME").cumprod() + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 6.0 0.0 2.0 2.0 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> ds.resample(time="3ME").cumprod(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 6.0 0.0 2.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -5592,57 +6890,69 @@ def count( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - DataArray.count - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").count() + Reduce this DataArray's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + DataArray.count + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").count() + Size: 24B + array([1, 2, 2]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -5672,57 +6982,69 @@ def all( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - DataArray.all - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").all() + Reduce this DataArray's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + DataArray.all + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 6B + array([ True, True, True, True, True, False]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").all() + Size: 3B + array([False, True, True]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -5752,57 +7074,69 @@ def any( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - DataArray.any - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").any() + Reduce this DataArray's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + DataArray.any + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 6B + array([ True, True, True, True, True, False]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").any() + Size: 3B + array([ True, True, True]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -5833,66 +7167,82 @@ def max( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - DataArray.max - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").max() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.groupby("labels").max(skipna=False) + Reduce this DataArray's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + DataArray.max + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").max() + Size: 24B + array([1., 2., 3.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.groupby("labels").max(skipna=False) + Size: 24B + array([nan, 2., 3.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -5925,66 +7275,82 @@ def min( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - DataArray.min - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").min() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.groupby("labels").min(skipna=False) + Reduce this DataArray's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + DataArray.min + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").min() + Size: 24B + array([1., 2., 0.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.groupby("labels").min(skipna=False) + Size: 24B + array([nan, 2., 0.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6017,68 +7383,84 @@ def mean( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - DataArray.mean - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").mean() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.groupby("labels").mean(skipna=False) + Reduce this DataArray's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + DataArray.mean + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").mean() + Size: 24B + array([1. , 2. , 1.5]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.groupby("labels").mean(skipna=False) + Size: 24B + array([nan, 2. , 1.5]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6112,78 +7494,98 @@ def prod( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - DataArray.prod - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").prod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.groupby("labels").prod(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> da.groupby("labels").prod(skipna=True, min_count=2) + Reduce this DataArray's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + DataArray.prod + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").prod() + Size: 24B + array([1., 4., 0.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.groupby("labels").prod(skipna=False) + Size: 24B + array([nan, 4., 0.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> da.groupby("labels").prod(skipna=True, min_count=2) + Size: 24B + array([nan, 4., 0.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6219,78 +7621,98 @@ def sum( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - DataArray.sum - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").sum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.groupby("labels").sum(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> da.groupby("labels").sum(skipna=True, min_count=2) + Reduce this DataArray's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + DataArray.sum + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").sum() + Size: 24B + array([1., 4., 3.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.groupby("labels").sum(skipna=False) + Size: 24B + array([nan, 4., 3.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> da.groupby("labels").sum(skipna=True, min_count=2) + Size: 24B + array([nan, 4., 3.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6326,75 +7748,95 @@ def std( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - DataArray.std - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").std() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.groupby("labels").std(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> da.groupby("labels").std(skipna=True, ddof=1) + Reduce this DataArray's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + DataArray.std + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").std() + Size: 24B + array([0. , 0. , 1.5]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.groupby("labels").std(skipna=False) + Size: 24B + array([nan, 0. , 1.5]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Specify ``ddof=1`` for an unbiased estimate. + + >>> da.groupby("labels").std(skipna=True, ddof=1) + Size: 24B + array([ nan, 0. , 2.12132034]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6430,75 +7872,95 @@ def var( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - DataArray.var - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").var() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.groupby("labels").var(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> da.groupby("labels").var(skipna=True, ddof=1) + Reduce this DataArray's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + DataArray.var + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").var() + Size: 24B + array([0. , 0. , 2.25]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.groupby("labels").var(skipna=False) + Size: 24B + array([ nan, 0. , 2.25]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Specify ``ddof=1`` for an unbiased estimate. + + >>> da.groupby("labels").var(skipna=True, ddof=1) + Size: 24B + array([nan, 0. , 4.5]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6533,68 +7995,84 @@ def median( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - DataArray.median - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").median() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.groupby("labels").median(skipna=False) + Reduce this DataArray's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + DataArray.median + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").median() + Size: 24B + array([1. , 2. , 1.5]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.groupby("labels").median(skipna=False) + Size: 24B + array([nan, 2. , 1.5]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ return self.reduce( duck_array_ops.median, @@ -6613,73 +8091,91 @@ def cumsum( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - DataArray.cumsum - DataArray.cumulative - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").cumsum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.groupby("labels").cumsum(skipna=False) + Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + DataArray.cumsum + DataArray.cumulative + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").cumsum() + Size: 48B + array([1., 2., 3., 3., 4., 1.]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").cumsum(skipna=False) + Size: 48B + array([ 1., 2., 3., 3., 4., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) DataArray: """ - Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - DataArray.cumprod - DataArray.cumulative - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.groupby("labels").cumprod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.groupby("labels").cumprod(skipna=False) + Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + DataArray.cumprod + DataArray.cumulative + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").cumprod() + Size: 48B + array([1., 2., 3., 0., 4., 1.]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.groupby("labels").cumprod(skipna=False) + Size: 48B + array([ 1., 2., 3., 0., 4., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) DataArray: """ - Reduce this DataArray's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - DataArray.count - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").count() + Reduce this DataArray's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + DataArray.count + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").count() + Size: 24B + array([1, 3, 1]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -6885,57 +8411,69 @@ def all( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - DataArray.all - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").all() + Reduce this DataArray's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + DataArray.all + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 6B + array([ True, True, True, True, True, False]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").all() + Size: 3B + array([ True, True, False]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -6965,57 +8503,69 @@ def any( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - DataArray.any - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").any() + Reduce this DataArray's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + DataArray.any + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 6B + array([ True, True, True, True, True, False]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").any() + Size: 3B + array([ True, True, True]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7046,66 +8596,82 @@ def max( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - DataArray.max - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").max() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.resample(time="3ME").max(skipna=False) + Reduce this DataArray's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + DataArray.max + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").max() + Size: 24B + array([1., 3., 2.]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.resample(time="3ME").max(skipna=False) + Size: 24B + array([ 1., 3., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7138,66 +8704,82 @@ def min( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - DataArray.min - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").min() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.resample(time="3ME").min(skipna=False) + Reduce this DataArray's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + DataArray.min + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").min() + Size: 24B + array([1., 0., 2.]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.resample(time="3ME").min(skipna=False) + Size: 24B + array([ 1., 0., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7230,68 +8812,84 @@ def mean( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - DataArray.mean - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").mean() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.resample(time="3ME").mean(skipna=False) + Reduce this DataArray's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + DataArray.mean + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").mean() + Size: 24B + array([1. , 1.66666667, 2. ]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.resample(time="3ME").mean(skipna=False) + Size: 24B + array([1. , 1.66666667, nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7325,78 +8923,98 @@ def prod( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - DataArray.prod - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").prod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.resample(time="3ME").prod(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> da.resample(time="3ME").prod(skipna=True, min_count=2) + Reduce this DataArray's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + DataArray.prod + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").prod() + Size: 24B + array([1., 0., 2.]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.resample(time="3ME").prod(skipna=False) + Size: 24B + array([ 1., 0., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> da.resample(time="3ME").prod(skipna=True, min_count=2) + Size: 24B + array([nan, 0., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7432,78 +9050,98 @@ def sum( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - DataArray.sum - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").sum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.resample(time="3ME").sum(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> da.resample(time="3ME").sum(skipna=True, min_count=2) + Reduce this DataArray's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + DataArray.sum + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").sum() + Size: 24B + array([1., 5., 2.]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.resample(time="3ME").sum(skipna=False) + Size: 24B + array([ 1., 5., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> da.resample(time="3ME").sum(skipna=True, min_count=2) + Size: 24B + array([nan, 5., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7539,75 +9177,95 @@ def std( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - DataArray.std - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").std() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.resample(time="3ME").std(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> da.resample(time="3ME").std(skipna=True, ddof=1) + Reduce this DataArray's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + DataArray.std + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").std() + Size: 24B + array([0. , 1.24721913, 0. ]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.resample(time="3ME").std(skipna=False) + Size: 24B + array([0. , 1.24721913, nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Specify ``ddof=1`` for an unbiased estimate. + + >>> da.resample(time="3ME").std(skipna=True, ddof=1) + Size: 24B + array([ nan, 1.52752523, nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7643,75 +9301,95 @@ def var( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - DataArray.var - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").var() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.resample(time="3ME").var(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> da.resample(time="3ME").var(skipna=True, ddof=1) + Reduce this DataArray's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + DataArray.var + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").var() + Size: 24B + array([0. , 1.55555556, 0. ]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.resample(time="3ME").var(skipna=False) + Size: 24B + array([0. , 1.55555556, nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Specify ``ddof=1`` for an unbiased estimate. + + >>> da.resample(time="3ME").var(skipna=True, ddof=1) + Size: 24B + array([ nan, 2.33333333, nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7746,68 +9424,84 @@ def median( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - DataArray.median - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").median() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.resample(time="3ME").median(skipna=False) + Reduce this DataArray's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + DataArray.median + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").median() + Size: 24B + array([1., 2., 2.]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + + Use ``skipna`` to control whether NaNs are ignored. + + >>> da.resample(time="3ME").median(skipna=False) + Size: 24B + array([ 1., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ return self.reduce( duck_array_ops.median, @@ -7826,73 +9520,91 @@ def cumsum( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - DataArray.cumsum - DataArray.cumulative - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").cumsum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.resample(time="3ME").cumsum(skipna=False) + Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + DataArray.cumsum + DataArray.cumulative + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").cumsum() + Size: 48B + array([1., 2., 5., 5., 2., 2.]) + Coordinates: + labels (time) >> da.resample(time="3ME").cumsum(skipna=False) + Size: 48B + array([ 1., 2., 5., 5., 2., nan]) + Coordinates: + labels (time) DataArray: """ - Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - DataArray.cumprod - DataArray.cumulative - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da - - >>> da.resample(time="3ME").cumprod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> da.resample(time="3ME").cumprod(skipna=False) + Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + DataArray.cumprod + DataArray.cumulative + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) >> da.resample(time="3ME").cumprod() + Size: 48B + array([1., 2., 6., 0., 2., 2.]) + Coordinates: + labels (time) >> da.resample(time="3ME").cumprod(skipna=False) + Size: 48B + array([ 1., 2., 6., 0., 2., nan]) + Coordinates: + labels (time) Self: """ - Reduce this NamedArray's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - Dataset.count - DataArray.count - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na - - >>> na.count() + Reduce this NamedArray's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + Dataset.count + DataArray.count + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + + >>> na.count() + Size: 8B + array(5) """ return self.reduce( duck_array_ops.count, @@ -77,42 +81,46 @@ def all( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - Dataset.all - DataArray.all - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray( - ... "x", np.array([True, True, True, True, True, False], dtype=bool) - ... ) - >>> na - - >>> na.all() + Reduce this NamedArray's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + Dataset.all + DataArray.all + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray( + ... "x", np.array([True, True, True, True, True, False], dtype=bool) + ... ) + >>> na + Size: 6B + array([ True, True, True, True, True, False]) + + >>> na.all() + Size: 1B + array(False) """ return self.reduce( duck_array_ops.array_all, @@ -126,42 +134,46 @@ def any( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - Dataset.any - DataArray.any - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray( - ... "x", np.array([True, True, True, True, True, False], dtype=bool) - ... ) - >>> na - - >>> na.any() + Reduce this NamedArray's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + Dataset.any + DataArray.any + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray( + ... "x", np.array([True, True, True, True, True, False], dtype=bool) + ... ) + >>> na + Size: 6B + array([ True, True, True, True, True, False]) + + >>> na.any() + Size: 1B + array(True) """ return self.reduce( duck_array_ops.array_any, @@ -177,49 +189,55 @@ def max( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - Dataset.max - DataArray.max - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na - - >>> na.max() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> na.max(skipna=False) + Reduce this NamedArray's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + Dataset.max + DataArray.max + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + + >>> na.max() + Size: 8B + array(3.) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> na.max(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.max, @@ -236,49 +254,55 @@ def min( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - Dataset.min - DataArray.min - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na - - >>> na.min() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> na.min(skipna=False) + Reduce this NamedArray's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + Dataset.min + DataArray.min + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + + >>> na.min() + Size: 8B + array(0.) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> na.min(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.min, @@ -295,53 +319,59 @@ def mean( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - Dataset.mean - DataArray.mean - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na - - >>> na.mean() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> na.mean(skipna=False) + Reduce this NamedArray's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + Dataset.mean + DataArray.mean + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + + >>> na.mean() + Size: 8B + array(1.6) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> na.mean(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.mean, @@ -359,63 +389,71 @@ def prod( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - Dataset.prod - DataArray.prod - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na - - >>> na.prod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> na.prod(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> na.prod(skipna=True, min_count=2) + Reduce this NamedArray's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + Dataset.prod + DataArray.prod + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + + >>> na.prod() + Size: 8B + array(0.) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> na.prod(skipna=False) + Size: 8B + array(nan) + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> na.prod(skipna=True, min_count=2) + Size: 8B + array(0.) """ return self.reduce( duck_array_ops.prod, @@ -434,63 +472,71 @@ def sum( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - Dataset.sum - DataArray.sum - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na - - >>> na.sum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> na.sum(skipna=False) - - Specify ``min_count`` for finer control over when NaNs are ignored. - - >>> na.sum(skipna=True, min_count=2) + Reduce this NamedArray's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + Dataset.sum + DataArray.sum + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + + >>> na.sum() + Size: 8B + array(8.) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> na.sum(skipna=False) + Size: 8B + array(nan) + + Specify ``min_count`` for finer control over when NaNs are ignored. + + >>> na.sum(skipna=True, min_count=2) + Size: 8B + array(8.) """ return self.reduce( duck_array_ops.sum, @@ -509,60 +555,68 @@ def std( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - Dataset.std - DataArray.std - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na - - >>> na.std() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> na.std(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> na.std(skipna=True, ddof=1) + Reduce this NamedArray's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + Dataset.std + DataArray.std + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + + >>> na.std() + Size: 8B + array(1.0198039) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> na.std(skipna=False) + Size: 8B + array(nan) + + Specify ``ddof=1`` for an unbiased estimate. + + >>> na.std(skipna=True, ddof=1) + Size: 8B + array(1.14017543) """ return self.reduce( duck_array_ops.std, @@ -581,60 +635,68 @@ def var( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - Dataset.var - DataArray.var - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na - - >>> na.var() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> na.var(skipna=False) - - Specify ``ddof=1`` for an unbiased estimate. - - >>> na.var(skipna=True, ddof=1) + Reduce this NamedArray's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + Dataset.var + DataArray.var + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + + >>> na.var() + Size: 8B + array(1.04) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> na.var(skipna=False) + Size: 8B + array(nan) + + Specify ``ddof=1`` for an unbiased estimate. + + >>> na.var(skipna=True, ddof=1) + Size: 8B + array(1.3) """ return self.reduce( duck_array_ops.var, @@ -652,53 +714,59 @@ def median( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - Dataset.median - DataArray.median - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na - - >>> na.median() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> na.median(skipna=False) + Reduce this NamedArray's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + Dataset.median + DataArray.median + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + + >>> na.median() + Size: 8B + array(2.) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> na.median(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.median, @@ -715,58 +783,64 @@ def cumsum( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - Dataset.cumsum - DataArray.cumsum - NamedArray.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na - - >>> na.cumsum() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> na.cumsum(skipna=False) + Reduce this NamedArray's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + Dataset.cumsum + DataArray.cumsum + NamedArray.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + + >>> na.cumsum() + Size: 48B + array([1., 3., 6., 6., 8., 8.]) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> na.cumsum(skipna=False) + Size: 48B + array([ 1., 3., 6., 6., 8., nan]) """ return self.reduce( duck_array_ops.cumsum, @@ -783,58 +857,64 @@ def cumprod( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - Dataset.cumprod - DataArray.cumprod - NamedArray.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na - - >>> na.cumprod() - - Use ``skipna`` to control whether NaNs are ignored. - - >>> na.cumprod(skipna=False) + Reduce this NamedArray's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + Dataset.cumprod + DataArray.cumprod + NamedArray.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na + Size: 48B + array([ 1., 2., 3., 0., 2., nan]) + + >>> na.cumprod() + Size: 48B + array([1., 2., 6., 0., 0., 0.]) + + Use ``skipna`` to control whether NaNs are ignored. + + >>> na.cumprod(skipna=False) + Size: 48B + array([ 1., 2., 6., 0., 0., nan]) """ return self.reduce( duck_array_ops.cumprod, From a296702012248eb50afb65ec68d3e64456051d6b Mon Sep 17 00:00:00 2001 From: Ewan Short Date: Fri, 12 Dec 2025 21:59:15 +1100 Subject: [PATCH 3/4] fix docs --- xarray/core/_aggregations.py | 11619 ++++++++++++++++----------------- 1 file changed, 5651 insertions(+), 5968 deletions(-) diff --git a/xarray/core/_aggregations.py b/xarray/core/_aggregations.py index 479c7e4e56d..adc064840de 100644 --- a/xarray/core/_aggregations.py +++ b/xarray/core/_aggregations.py @@ -42,57 +42,52 @@ def count( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - Dataset.count - DataArray.count - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + Dataset.count + DataArray.count + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -102,12 +97,12 @@ def count( Data variables: foo (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> dt.count() - - Group: / - Dimensions: () - Data variables: - foo int64 8B 5 + >>> dt.count() + + Group: / + Dimensions: () + Data variables: + foo int64 8B 5 """ return self.reduce( duck_array_ops.count, @@ -125,63 +120,57 @@ def all( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - Dataset.all - DataArray.all - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=( - ... "time", - ... np.array( - ... [True, True, True, True, True, False], - ... dtype=bool, - ... ), - ... ) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + Dataset.all + DataArray.all + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=( + ... "time", + ... np.array([True, True, True, True, True, False], dtype=bool), + ... ) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -191,12 +180,12 @@ def all( Data variables: foo (time) bool 6B True True True True True False - >>> dt.all() - - Group: / - Dimensions: () - Data variables: - foo bool 1B False + >>> dt.all() + + Group: / + Dimensions: () + Data variables: + foo bool 1B False """ return self.reduce( duck_array_ops.array_all, @@ -214,63 +203,57 @@ def any( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - Dataset.any - DataArray.any - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=( - ... "time", - ... np.array( - ... [True, True, True, True, True, False], - ... dtype=bool, - ... ), - ... ) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + Dataset.any + DataArray.any + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict( + ... foo=( + ... "time", + ... np.array([True, True, True, True, True, False], dtype=bool), + ... ) + ... ), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -280,12 +263,12 @@ def any( Data variables: foo (time) bool 6B True True True True True False - >>> dt.any() - - Group: / - Dimensions: () - Data variables: - foo bool 1B True + >>> dt.any() + + Group: / + Dimensions: () + Data variables: + foo bool 1B True """ return self.reduce( duck_array_ops.array_any, @@ -304,62 +287,57 @@ def max( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - Dataset.max - DataArray.max - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + Dataset.max + DataArray.max + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -369,21 +347,21 @@ def max( Data variables: foo (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> dt.max() + >>> dt.max() Group: / Dimensions: () Data variables: foo float64 8B 3.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> dt.max(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan + >>> dt.max(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan """ return self.reduce( duck_array_ops.max, @@ -403,62 +381,57 @@ def min( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - Dataset.min - DataArray.min - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + Dataset.min + DataArray.min + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -468,21 +441,21 @@ def min( Data variables: foo (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> dt.min() + >>> dt.min() Group: / Dimensions: () Data variables: foo float64 8B 0.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> dt.min(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan + >>> dt.min(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan """ return self.reduce( duck_array_ops.min, @@ -502,66 +475,61 @@ def mean( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - Dataset.mean - DataArray.mean - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + Dataset.mean + DataArray.mean + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -571,21 +539,21 @@ def mean( Data variables: foo (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> dt.mean() + >>> dt.mean() Group: / Dimensions: () Data variables: foo float64 8B 1.6 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> dt.mean(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan + >>> dt.mean(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan """ return self.reduce( duck_array_ops.mean, @@ -606,72 +574,67 @@ def prod( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - Dataset.prod - DataArray.prod - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + Dataset.prod + DataArray.prod + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -681,30 +644,30 @@ def prod( Data variables: foo (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> dt.prod() + >>> dt.prod() Group: / Dimensions: () Data variables: foo float64 8B 0.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> dt.prod(skipna=False) + >>> dt.prod(skipna=False) Group: / Dimensions: () Data variables: foo float64 8B nan - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> dt.prod(skipna=True, min_count=2) - - Group: / - Dimensions: () - Data variables: - foo float64 8B 0.0 + >>> dt.prod(skipna=True, min_count=2) + + Group: / + Dimensions: () + Data variables: + foo float64 8B 0.0 """ return self.reduce( duck_array_ops.prod, @@ -726,72 +689,67 @@ def sum( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - Dataset.sum - DataArray.sum - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + Dataset.sum + DataArray.sum + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -801,30 +759,30 @@ def sum( Data variables: foo (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> dt.sum() + >>> dt.sum() Group: / Dimensions: () Data variables: foo float64 8B 8.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> dt.sum(skipna=False) + >>> dt.sum(skipna=False) Group: / Dimensions: () Data variables: foo float64 8B nan - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> dt.sum(skipna=True, min_count=2) - - Group: / - Dimensions: () - Data variables: - foo float64 8B 8.0 + >>> dt.sum(skipna=True, min_count=2) + + Group: / + Dimensions: () + Data variables: + foo float64 8B 8.0 """ return self.reduce( duck_array_ops.sum, @@ -846,69 +804,64 @@ def std( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - Dataset.std - DataArray.std - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + Dataset.std + DataArray.std + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -918,30 +871,30 @@ def std( Data variables: foo (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> dt.std() + >>> dt.std() Group: / Dimensions: () Data variables: foo float64 8B 1.02 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> dt.std(skipna=False) + >>> dt.std(skipna=False) Group: / Dimensions: () Data variables: foo float64 8B nan - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> dt.std(skipna=True, ddof=1) - - Group: / - Dimensions: () - Data variables: - foo float64 8B 1.14 + >>> dt.std(skipna=True, ddof=1) + + Group: / + Dimensions: () + Data variables: + foo float64 8B 1.14 """ return self.reduce( duck_array_ops.std, @@ -963,69 +916,64 @@ def var( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - Dataset.var - DataArray.var - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + Dataset.var + DataArray.var + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -1035,30 +983,30 @@ def var( Data variables: foo (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> dt.var() + >>> dt.var() Group: / Dimensions: () Data variables: foo float64 8B 1.04 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> dt.var(skipna=False) + >>> dt.var(skipna=False) Group: / Dimensions: () Data variables: foo float64 8B nan - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> dt.var(skipna=True, ddof=1) - - Group: / - Dimensions: () - Data variables: - foo float64 8B 1.3 + >>> dt.var(skipna=True, ddof=1) + + Group: / + Dimensions: () + Data variables: + foo float64 8B 1.3 """ return self.reduce( duck_array_ops.var, @@ -1079,66 +1027,61 @@ def median( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - Dataset.median - DataArray.median - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + Dataset.median + DataArray.median + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -1148,21 +1091,21 @@ def median( Data variables: foo (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> dt.median() + >>> dt.median() Group: / Dimensions: () Data variables: foo float64 8B 2.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> dt.median(skipna=False) - - Group: / - Dimensions: () - Data variables: - foo float64 8B nan + >>> dt.median(skipna=False) + + Group: / + Dimensions: () + Data variables: + foo float64 8B nan """ return self.reduce( duck_array_ops.median, @@ -1182,71 +1125,66 @@ def cumsum( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - Dataset.cumsum - DataArray.cumsum - DataTree.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + Dataset.cumsum + DataArray.cumsum + DataTree.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -1256,7 +1194,7 @@ def cumsum( Data variables: foo (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> dt.cumsum() + >>> dt.cumsum() Group: / Dimensions: (time: 6) @@ -1264,15 +1202,15 @@ def cumsum( Data variables: foo (time) float64 48B 1.0 3.0 6.0 6.0 8.0 8.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> dt.cumsum(skipna=False) - - Group: / - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - foo (time) float64 48B 1.0 3.0 6.0 6.0 8.0 nan + >>> dt.cumsum(skipna=False) + + Group: / + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + foo (time) float64 48B 1.0 3.0 6.0 6.0 8.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -1292,71 +1230,66 @@ def cumprod( **kwargs: Any, ) -> Self: """ - Reduce this DataTree's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataTree - New DataTree with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - Dataset.cumprod - DataArray.cumprod - DataTree.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> dt = xr.DataTree( - ... xr.Dataset( - ... data_vars=dict( - ... foo=("time", np.array([1, 2, 3, 0, 2, np.nan])) - ... ), - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=( - ... "time", - ... np.array(["a", "b", "c", "c", "b", "a"]), - ... ), - ... ), - ... ), - ... ) - >>> dt + Reduce this DataTree's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataTree + New DataTree with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + Dataset.cumprod + DataArray.cumprod + DataTree.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> dt = xr.DataTree( + ... xr.Dataset( + ... data_vars=dict(foo=("time", np.array([1, 2, 3, 0, 2, np.nan]))), + ... coords=dict( + ... time=( + ... "time", + ... pd.date_range("2001-01-01", freq="ME", periods=6), + ... ), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ), + ... ) + >>> dt Group: / Dimensions: (time: 6) @@ -1366,7 +1299,7 @@ def cumprod( Data variables: foo (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> dt.cumprod() + >>> dt.cumprod() Group: / Dimensions: (time: 6) @@ -1374,15 +1307,15 @@ def cumprod( Data variables: foo (time) float64 48B 1.0 2.0 6.0 0.0 0.0 0.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> dt.cumprod(skipna=False) - - Group: / - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - foo (time) float64 48B 1.0 2.0 6.0 0.0 0.0 nan + >>> dt.cumprod(skipna=False) + + Group: / + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + foo (time) float64 48B 1.0 2.0 6.0 0.0 0.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -1417,51 +1350,48 @@ def count( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - DataArray.count - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + DataArray.count + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -1470,11 +1400,11 @@ def count( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.count() - Size: 8B - Dimensions: () - Data variables: - da int64 8B 5 + >>> ds.count() + Size: 8B + Dimensions: () + Data variables: + da int64 8B 5 """ return self.reduce( duck_array_ops.count, @@ -1492,51 +1422,48 @@ def all( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - DataArray.all - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + DataArray.all + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 78B Dimensions: (time: 6) Coordinates: @@ -1545,11 +1472,11 @@ def all( Data variables: da (time) bool 6B True True True True True False - >>> ds.all() - Size: 1B - Dimensions: () - Data variables: - da bool 1B False + >>> ds.all() + Size: 1B + Dimensions: () + Data variables: + da bool 1B False """ return self.reduce( duck_array_ops.array_all, @@ -1567,51 +1494,48 @@ def any( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - DataArray.any - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + DataArray.any + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 78B Dimensions: (time: 6) Coordinates: @@ -1620,11 +1544,11 @@ def any( Data variables: da (time) bool 6B True True True True True False - >>> ds.any() - Size: 1B - Dimensions: () - Data variables: - da bool 1B True + >>> ds.any() + Size: 1B + Dimensions: () + Data variables: + da bool 1B True """ return self.reduce( duck_array_ops.array_any, @@ -1643,56 +1567,53 @@ def max( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - DataArray.max - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + DataArray.max + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -1701,19 +1622,19 @@ def max( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.max() + >>> ds.max() Size: 8B Dimensions: () Data variables: da float64 8B 3.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.max(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan + >>> ds.max(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan """ return self.reduce( duck_array_ops.max, @@ -1733,56 +1654,53 @@ def min( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - DataArray.min - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + DataArray.min + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -1791,19 +1709,19 @@ def min( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.min() + >>> ds.min() Size: 8B Dimensions: () Data variables: da float64 8B 0.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.min(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan + >>> ds.min(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan """ return self.reduce( duck_array_ops.min, @@ -1823,60 +1741,53 @@ def mean( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - DataArray.mean - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + DataArray.mean + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -1885,19 +1796,19 @@ def mean( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.mean() + >>> ds.mean() Size: 8B Dimensions: () Data variables: da float64 8B 1.6 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.mean(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan + >>> ds.mean(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan """ return self.reduce( duck_array_ops.mean, @@ -1918,66 +1829,63 @@ def prod( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - DataArray.prod - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + DataArray.prod + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -1986,27 +1894,27 @@ def prod( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.prod() + >>> ds.prod() Size: 8B Dimensions: () Data variables: da float64 8B 0.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.prod(skipna=False) + >>> ds.prod(skipna=False) Size: 8B Dimensions: () Data variables: da float64 8B nan - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> ds.prod(skipna=True, min_count=2) - Size: 8B - Dimensions: () - Data variables: - da float64 8B 0.0 + >>> ds.prod(skipna=True, min_count=2) + Size: 8B + Dimensions: () + Data variables: + da float64 8B 0.0 """ return self.reduce( duck_array_ops.prod, @@ -2028,66 +1936,63 @@ def sum( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - DataArray.sum - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + DataArray.sum + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -2096,27 +2001,27 @@ def sum( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.sum() + >>> ds.sum() Size: 8B Dimensions: () Data variables: da float64 8B 8.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.sum(skipna=False) + >>> ds.sum(skipna=False) Size: 8B Dimensions: () Data variables: da float64 8B nan - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> ds.sum(skipna=True, min_count=2) - Size: 8B - Dimensions: () - Data variables: - da float64 8B 8.0 + >>> ds.sum(skipna=True, min_count=2) + Size: 8B + Dimensions: () + Data variables: + da float64 8B 8.0 """ return self.reduce( duck_array_ops.sum, @@ -2138,63 +2043,60 @@ def std( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - DataArray.std - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + DataArray.std + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -2203,27 +2105,27 @@ def std( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.std() + >>> ds.std() Size: 8B Dimensions: () Data variables: da float64 8B 1.02 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.std(skipna=False) + >>> ds.std(skipna=False) Size: 8B Dimensions: () Data variables: da float64 8B nan - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> ds.std(skipna=True, ddof=1) - Size: 8B - Dimensions: () - Data variables: - da float64 8B 1.14 + >>> ds.std(skipna=True, ddof=1) + Size: 8B + Dimensions: () + Data variables: + da float64 8B 1.14 """ return self.reduce( duck_array_ops.std, @@ -2245,63 +2147,60 @@ def var( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - DataArray.var - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + DataArray.var + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -2310,27 +2209,27 @@ def var( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.var() + >>> ds.var() Size: 8B Dimensions: () Data variables: da float64 8B 1.04 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.var(skipna=False) + >>> ds.var(skipna=False) Size: 8B Dimensions: () Data variables: da float64 8B nan - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> ds.var(skipna=True, ddof=1) - Size: 8B - Dimensions: () - Data variables: - da float64 8B 1.3 + >>> ds.var(skipna=True, ddof=1) + Size: 8B + Dimensions: () + Data variables: + da float64 8B 1.3 """ return self.reduce( duck_array_ops.var, @@ -2351,60 +2250,57 @@ def median( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - DataArray.median - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + DataArray.median + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -2413,19 +2309,19 @@ def median( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.median() + >>> ds.median() Size: 8B Dimensions: () Data variables: da float64 8B 2.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.median(skipna=False) - Size: 8B - Dimensions: () - Data variables: - da float64 8B nan + >>> ds.median(skipna=False) + Size: 8B + Dimensions: () + Data variables: + da float64 8B nan """ return self.reduce( duck_array_ops.median, @@ -2445,65 +2341,62 @@ def cumsum( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - DataArray.cumsum - Dataset.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + DataArray.cumsum + Dataset.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -2512,21 +2405,21 @@ def cumsum( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.cumsum() + >>> ds.cumsum() Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 3.0 6.0 6.0 8.0 8.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.cumsum(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 3.0 6.0 6.0 8.0 nan + >>> ds.cumsum(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 3.0 6.0 6.0 8.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -2546,65 +2439,62 @@ def cumprod( **kwargs: Any, ) -> Self: """ - Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - DataArray.cumprod - Dataset.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + DataArray.cumprod + Dataset.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -2613,21 +2503,21 @@ def cumprod( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.cumprod() + >>> ds.cumprod() Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 6.0 0.0 0.0 0.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.cumprod(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 6.0 0.0 0.0 nan + >>> ds.cumprod(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 6.0 0.0 0.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -2662,59 +2552,56 @@ def count( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - Dataset.count - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + Dataset.count + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.count() - Size: 8B - array(5) + >>> da.count() + Size: 8B + array(5) """ return self.reduce( duck_array_ops.count, @@ -2731,59 +2618,56 @@ def all( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - Dataset.all - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + Dataset.all + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 6B array([ True, True, True, True, True, False]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.all() - Size: 1B - array(False) + >>> da.all() + Size: 1B + array(False) """ return self.reduce( duck_array_ops.array_all, @@ -2800,59 +2684,56 @@ def any( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - Dataset.any - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + Dataset.any + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 6B array([ True, True, True, True, True, False]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.any() - Size: 1B - array(True) + >>> da.any() + Size: 1B + array(True) """ return self.reduce( duck_array_ops.array_any, @@ -2870,70 +2751,67 @@ def max( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - Dataset.max - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + Dataset.max + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.max() + >>> da.max() Size: 8B array(3.) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.max(skipna=False) - Size: 8B - array(nan) + >>> da.max(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.max, @@ -2952,70 +2830,67 @@ def min( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - Dataset.min - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + Dataset.min + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.min() + >>> da.min() Size: 8B array(0.) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.min(skipna=False) - Size: 8B - array(nan) + >>> da.min(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.min, @@ -3034,74 +2909,67 @@ def mean( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - Dataset.mean - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + Dataset.mean + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.mean() + >>> da.mean() Size: 8B array(1.6) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.mean(skipna=False) - Size: 8B - array(nan) + >>> da.mean(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.mean, @@ -3121,86 +2989,83 @@ def prod( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - Dataset.prod - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + Dataset.prod + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.prod() + >>> da.prod() Size: 8B array(0.) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.prod(skipna=False) + >>> da.prod(skipna=False) Size: 8B array(nan) - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> da.prod(skipna=True, min_count=2) - Size: 8B - array(0.) + >>> da.prod(skipna=True, min_count=2) + Size: 8B + array(0.) """ return self.reduce( duck_array_ops.prod, @@ -3221,86 +3086,83 @@ def sum( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - Dataset.sum - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + Dataset.sum + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.sum() + >>> da.sum() Size: 8B array(8.) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.sum(skipna=False) + >>> da.sum(skipna=False) Size: 8B array(nan) - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> da.sum(skipna=True, min_count=2) - Size: 8B - array(8.) + >>> da.sum(skipna=True, min_count=2) + Size: 8B + array(8.) """ return self.reduce( duck_array_ops.sum, @@ -3321,83 +3183,80 @@ def std( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - Dataset.std - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + Dataset.std + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.std() + >>> da.std() Size: 8B array(1.0198039) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.std(skipna=False) + >>> da.std(skipna=False) Size: 8B array(nan) - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> da.std(skipna=True, ddof=1) - Size: 8B - array(1.14017543) + >>> da.std(skipna=True, ddof=1) + Size: 8B + array(1.14017543) """ return self.reduce( duck_array_ops.std, @@ -3418,83 +3277,80 @@ def var( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - Dataset.var - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + Dataset.var + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.var() + >>> da.var() Size: 8B array(1.04) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.var(skipna=False) + >>> da.var(skipna=False) Size: 8B array(nan) - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> da.var(skipna=True, ddof=1) - Size: 8B - array(1.3) + >>> da.var(skipna=True, ddof=1) + Size: 8B + array(1.3) """ return self.reduce( duck_array_ops.var, @@ -3514,74 +3370,71 @@ def median( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - Dataset.median - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + Dataset.median + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.median() + >>> da.median() Size: 8B array(2.) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.median(skipna=False) - Size: 8B - array(nan) + >>> da.median(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.median, @@ -3600,85 +3453,82 @@ def cumsum( **kwargs: Any, ) -> Self: """ - Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - Dataset.cumsum - DataArray.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + Dataset.cumsum + DataArray.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.cumsum() + >>> da.cumsum() Size: 48B array([1., 3., 6., 6., 8., 8.]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.cumsum(skipna=False) - Size: 48B - array([ 1., 3., 6., 6., 8., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.cumsum(skipna=False) + Size: 48B + array([ 1., 3., 6., 6., 8., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) Self: """ - Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - Dataset.cumprod - DataArray.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + Dataset.cumprod + DataArray.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.cumprod() + >>> da.cumprod() Size: 48B array([1., 2., 6., 0., 0., 0.]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.cumprod(skipna=False) - Size: 48B - array([ 1., 2., 6., 0., 0., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.cumprod(skipna=False) + Size: 48B + array([ 1., 2., 6., 0., 0., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) Dataset: """ - Reduce this Dataset's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - Dataset.count - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + Dataset.count + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -3877,13 +3721,13 @@ def count( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.groupby("labels").count() - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) int64 24B 1 2 2 + >>> ds.groupby("labels").count() + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) int64 24B 1 2 2 """ if ( flox_available @@ -3915,59 +3759,56 @@ def all( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - Dataset.all - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + Dataset.all + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 78B Dimensions: (time: 6) Coordinates: @@ -3976,13 +3817,13 @@ def all( Data variables: da (time) bool 6B True True True True True False - >>> ds.groupby("labels").all() - Size: 27B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) bool 3B False True True + >>> ds.groupby("labels").all() + Size: 27B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) bool 3B False True True """ if ( flox_available @@ -4014,59 +3855,56 @@ def any( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - Dataset.any - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + Dataset.any + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 78B Dimensions: (time: 6) Coordinates: @@ -4075,13 +3913,13 @@ def any( Data variables: da (time) bool 6B True True True True True False - >>> ds.groupby("labels").any() - Size: 27B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) bool 3B True True True + >>> ds.groupby("labels").any() + Size: 27B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) bool 3B True True True """ if ( flox_available @@ -4114,64 +3952,61 @@ def max( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - Dataset.max - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + Dataset.max + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -4180,7 +4015,7 @@ def max( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.groupby("labels").max() + >>> ds.groupby("labels").max() Size: 48B Dimensions: (labels: 3) Coordinates: @@ -4188,15 +4023,15 @@ def max( Data variables: da (labels) float64 24B 1.0 2.0 3.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.groupby("labels").max(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 2.0 3.0 + >>> ds.groupby("labels").max(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 2.0 3.0 """ if ( flox_available @@ -4231,64 +4066,61 @@ def min( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - Dataset.min - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + Dataset.min + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -4297,7 +4129,7 @@ def min( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.groupby("labels").min() + >>> ds.groupby("labels").min() Size: 48B Dimensions: (labels: 3) Coordinates: @@ -4305,15 +4137,15 @@ def min( Data variables: da (labels) float64 24B 1.0 2.0 0.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.groupby("labels").min(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 2.0 0.0 + >>> ds.groupby("labels").min(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 2.0 0.0 """ if ( flox_available @@ -4348,66 +4180,61 @@ def mean( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - Dataset.mean - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + Dataset.mean + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -4416,7 +4243,7 @@ def mean( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.groupby("labels").mean() + >>> ds.groupby("labels").mean() Size: 48B Dimensions: (labels: 3) Coordinates: @@ -4424,15 +4251,15 @@ def mean( Data variables: da (labels) float64 24B 1.0 2.0 1.5 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.groupby("labels").mean(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 2.0 1.5 + >>> ds.groupby("labels").mean(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 2.0 1.5 """ if ( flox_available @@ -4468,72 +4295,69 @@ def prod( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - Dataset.prod - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + Dataset.prod + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -4542,7 +4366,7 @@ def prod( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.groupby("labels").prod() + >>> ds.groupby("labels").prod() Size: 48B Dimensions: (labels: 3) Coordinates: @@ -4550,9 +4374,9 @@ def prod( Data variables: da (labels) float64 24B 1.0 4.0 0.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.groupby("labels").prod(skipna=False) + >>> ds.groupby("labels").prod(skipna=False) Size: 48B Dimensions: (labels: 3) Coordinates: @@ -4560,15 +4384,15 @@ def prod( Data variables: da (labels) float64 24B nan 4.0 0.0 - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> ds.groupby("labels").prod(skipna=True, min_count=2) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 4.0 0.0 + >>> ds.groupby("labels").prod(skipna=True, min_count=2) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 4.0 0.0 """ if ( flox_available @@ -4606,72 +4430,69 @@ def sum( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - Dataset.sum - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + Dataset.sum + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -4680,7 +4501,7 @@ def sum( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.groupby("labels").sum() + >>> ds.groupby("labels").sum() Size: 48B Dimensions: (labels: 3) Coordinates: @@ -4688,9 +4509,9 @@ def sum( Data variables: da (labels) float64 24B 1.0 4.0 3.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.groupby("labels").sum(skipna=False) + >>> ds.groupby("labels").sum(skipna=False) Size: 48B Dimensions: (labels: 3) Coordinates: @@ -4698,15 +4519,15 @@ def sum( Data variables: da (labels) float64 24B nan 4.0 3.0 - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> ds.groupby("labels").sum(skipna=True, min_count=2) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 4.0 3.0 + >>> ds.groupby("labels").sum(skipna=True, min_count=2) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 4.0 3.0 """ if ( flox_available @@ -4744,69 +4565,66 @@ def std( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - Dataset.std - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + Dataset.std + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -4815,7 +4633,7 @@ def std( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.groupby("labels").std() + >>> ds.groupby("labels").std() Size: 48B Dimensions: (labels: 3) Coordinates: @@ -4823,9 +4641,9 @@ def std( Data variables: da (labels) float64 24B 0.0 0.0 1.5 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.groupby("labels").std(skipna=False) + >>> ds.groupby("labels").std(skipna=False) Size: 48B Dimensions: (labels: 3) Coordinates: @@ -4833,15 +4651,15 @@ def std( Data variables: da (labels) float64 24B nan 0.0 1.5 - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> ds.groupby("labels").std(skipna=True, ddof=1) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 0.0 2.121 + >>> ds.groupby("labels").std(skipna=True, ddof=1) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 0.0 2.121 """ if ( flox_available @@ -4879,69 +4697,66 @@ def var( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - Dataset.var - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + Dataset.var + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -4950,7 +4765,7 @@ def var( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.groupby("labels").var() + >>> ds.groupby("labels").var() Size: 48B Dimensions: (labels: 3) Coordinates: @@ -4958,9 +4773,9 @@ def var( Data variables: da (labels) float64 24B 0.0 0.0 2.25 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.groupby("labels").var(skipna=False) + >>> ds.groupby("labels").var(skipna=False) Size: 48B Dimensions: (labels: 3) Coordinates: @@ -4968,15 +4783,15 @@ def var( Data variables: da (labels) float64 24B nan 0.0 2.25 - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> ds.groupby("labels").var(skipna=True, ddof=1) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 0.0 4.5 + >>> ds.groupby("labels").var(skipna=True, ddof=1) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 0.0 4.5 """ if ( flox_available @@ -5013,66 +4828,63 @@ def median( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - Dataset.median - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + Dataset.median + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -5081,7 +4893,7 @@ def median( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.groupby("labels").median() + >>> ds.groupby("labels").median() Size: 48B Dimensions: (labels: 3) Coordinates: @@ -5089,15 +4901,15 @@ def median( Data variables: da (labels) float64 24B 1.0 2.0 1.5 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.groupby("labels").median(skipna=False) - Size: 48B - Dimensions: (labels: 3) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' - Data variables: - da (labels) float64 24B nan 2.0 1.5 + >>> ds.groupby("labels").median(skipna=False) + Size: 48B + Dimensions: (labels: 3) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' + Data variables: + da (labels) float64 24B nan 2.0 1.5 """ return self.reduce( duck_array_ops.median, @@ -5117,71 +4929,68 @@ def cumsum( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - Dataset.cumsum - Dataset.cumulative - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + Dataset.cumsum + Dataset.cumulative + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -5190,21 +4999,21 @@ def cumsum( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.groupby("labels").cumsum() + >>> ds.groupby("labels").cumsum() Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 3.0 3.0 4.0 1.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.groupby("labels").cumsum(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 3.0 3.0 4.0 nan + >>> ds.groupby("labels").cumsum(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 3.0 3.0 4.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -5224,71 +5033,68 @@ def cumprod( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - Dataset.cumprod - Dataset.cumulative - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + Dataset.cumprod + Dataset.cumulative + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -5297,21 +5103,21 @@ def cumprod( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.groupby("labels").cumprod() + >>> ds.groupby("labels").cumprod() Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 4.0 1.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.groupby("labels").cumprod(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 3.0 0.0 4.0 nan + >>> ds.groupby("labels").cumprod(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 3.0 0.0 4.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -5353,59 +5159,56 @@ def count( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - Dataset.count - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + Dataset.count + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -5414,13 +5217,13 @@ def count( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.resample(time="3ME").count() - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) int64 24B 1 3 1 + >>> ds.resample(time="3ME").count() + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) int64 24B 1 3 1 """ if ( flox_available @@ -5452,59 +5255,56 @@ def all( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - Dataset.all - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + Dataset.all + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 78B Dimensions: (time: 6) Coordinates: @@ -5513,13 +5313,13 @@ def all( Data variables: da (time) bool 6B True True True True True False - >>> ds.resample(time="3ME").all() - Size: 27B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) bool 3B True True False + >>> ds.resample(time="3ME").all() + Size: 27B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) bool 3B True True False """ if ( flox_available @@ -5551,59 +5351,56 @@ def any( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - Dataset.any - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + Dataset.any + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 78B Dimensions: (time: 6) Coordinates: @@ -5612,13 +5409,13 @@ def any( Data variables: da (time) bool 6B True True True True True False - >>> ds.resample(time="3ME").any() - Size: 27B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) bool 3B True True True + >>> ds.resample(time="3ME").any() + Size: 27B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) bool 3B True True True """ if ( flox_available @@ -5651,64 +5448,61 @@ def max( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - Dataset.max - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + Dataset.max + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -5717,7 +5511,7 @@ def max( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.resample(time="3ME").max() + >>> ds.resample(time="3ME").max() Size: 48B Dimensions: (time: 3) Coordinates: @@ -5725,15 +5519,15 @@ def max( Data variables: da (time) float64 24B 1.0 3.0 2.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.resample(time="3ME").max(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 3.0 nan + >>> ds.resample(time="3ME").max(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 3.0 nan """ if ( flox_available @@ -5768,64 +5562,61 @@ def min( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - Dataset.min - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + Dataset.min + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -5834,7 +5625,7 @@ def min( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.resample(time="3ME").min() + >>> ds.resample(time="3ME").min() Size: 48B Dimensions: (time: 3) Coordinates: @@ -5842,15 +5633,15 @@ def min( Data variables: da (time) float64 24B 1.0 0.0 2.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.resample(time="3ME").min(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 0.0 nan + >>> ds.resample(time="3ME").min(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 0.0 nan """ if ( flox_available @@ -5885,66 +5676,61 @@ def mean( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - Dataset.mean - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + Dataset.mean + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -5953,7 +5739,7 @@ def mean( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.resample(time="3ME").mean() + >>> ds.resample(time="3ME").mean() Size: 48B Dimensions: (time: 3) Coordinates: @@ -5961,15 +5747,15 @@ def mean( Data variables: da (time) float64 24B 1.0 1.667 2.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.resample(time="3ME").mean(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 1.667 nan + >>> ds.resample(time="3ME").mean(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 1.667 nan """ if ( flox_available @@ -6005,72 +5791,69 @@ def prod( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - Dataset.prod - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + Dataset.prod + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -6079,7 +5862,7 @@ def prod( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.resample(time="3ME").prod() + >>> ds.resample(time="3ME").prod() Size: 48B Dimensions: (time: 3) Coordinates: @@ -6087,9 +5870,9 @@ def prod( Data variables: da (time) float64 24B 1.0 0.0 2.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.resample(time="3ME").prod(skipna=False) + >>> ds.resample(time="3ME").prod(skipna=False) Size: 48B Dimensions: (time: 3) Coordinates: @@ -6097,15 +5880,15 @@ def prod( Data variables: da (time) float64 24B 1.0 0.0 nan - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> ds.resample(time="3ME").prod(skipna=True, min_count=2) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B nan 0.0 nan + >>> ds.resample(time="3ME").prod(skipna=True, min_count=2) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B nan 0.0 nan """ if ( flox_available @@ -6143,72 +5926,69 @@ def sum( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - Dataset.sum - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + Dataset.sum + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -6217,7 +5997,7 @@ def sum( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.resample(time="3ME").sum() + >>> ds.resample(time="3ME").sum() Size: 48B Dimensions: (time: 3) Coordinates: @@ -6225,9 +6005,9 @@ def sum( Data variables: da (time) float64 24B 1.0 5.0 2.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.resample(time="3ME").sum(skipna=False) + >>> ds.resample(time="3ME").sum(skipna=False) Size: 48B Dimensions: (time: 3) Coordinates: @@ -6235,15 +6015,15 @@ def sum( Data variables: da (time) float64 24B 1.0 5.0 nan - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> ds.resample(time="3ME").sum(skipna=True, min_count=2) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B nan 5.0 nan + >>> ds.resample(time="3ME").sum(skipna=True, min_count=2) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B nan 5.0 nan """ if ( flox_available @@ -6281,69 +6061,66 @@ def std( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - Dataset.std - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + Dataset.std + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -6352,7 +6129,7 @@ def std( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.resample(time="3ME").std() + >>> ds.resample(time="3ME").std() Size: 48B Dimensions: (time: 3) Coordinates: @@ -6360,9 +6137,9 @@ def std( Data variables: da (time) float64 24B 0.0 1.247 0.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.resample(time="3ME").std(skipna=False) + >>> ds.resample(time="3ME").std(skipna=False) Size: 48B Dimensions: (time: 3) Coordinates: @@ -6370,15 +6147,15 @@ def std( Data variables: da (time) float64 24B 0.0 1.247 nan - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> ds.resample(time="3ME").std(skipna=True, ddof=1) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B nan 1.528 nan + >>> ds.resample(time="3ME").std(skipna=True, ddof=1) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B nan 1.528 nan """ if ( flox_available @@ -6416,69 +6193,66 @@ def var( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - Dataset.var - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + Dataset.var + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -6487,7 +6261,7 @@ def var( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.resample(time="3ME").var() + >>> ds.resample(time="3ME").var() Size: 48B Dimensions: (time: 3) Coordinates: @@ -6495,9 +6269,9 @@ def var( Data variables: da (time) float64 24B 0.0 1.556 0.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.resample(time="3ME").var(skipna=False) + >>> ds.resample(time="3ME").var(skipna=False) Size: 48B Dimensions: (time: 3) Coordinates: @@ -6505,15 +6279,15 @@ def var( Data variables: da (time) float64 24B 0.0 1.556 nan - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> ds.resample(time="3ME").var(skipna=True, ddof=1) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B nan 2.333 nan + >>> ds.resample(time="3ME").var(skipna=True, ddof=1) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B nan 2.333 nan """ if ( flox_available @@ -6550,66 +6324,63 @@ def median( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - Dataset.median - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + Dataset.median + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -6618,7 +6389,7 @@ def median( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.resample(time="3ME").median() + >>> ds.resample(time="3ME").median() Size: 48B Dimensions: (time: 3) Coordinates: @@ -6626,15 +6397,15 @@ def median( Data variables: da (time) float64 24B 1.0 2.0 2.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.resample(time="3ME").median(skipna=False) - Size: 48B - Dimensions: (time: 3) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Data variables: - da (time) float64 24B 1.0 2.0 nan + >>> ds.resample(time="3ME").median(skipna=False) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + Data variables: + da (time) float64 24B 1.0 2.0 nan """ return self.reduce( duck_array_ops.median, @@ -6654,71 +6425,68 @@ def cumsum( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - Dataset.cumsum - Dataset.cumulative - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + Dataset.cumsum + Dataset.cumulative + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -6727,21 +6495,21 @@ def cumsum( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.resample(time="3ME").cumsum() + >>> ds.resample(time="3ME").cumsum() Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 5.0 5.0 2.0 2.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.resample(time="3ME").cumsum(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 5.0 5.0 2.0 nan + >>> ds.resample(time="3ME").cumsum(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 5.0 5.0 2.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -6761,71 +6529,68 @@ def cumprod( **kwargs: Any, ) -> Dataset: """ - Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : Dataset - New Dataset with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - Dataset.cumprod - Dataset.cumulative - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> ds = xr.Dataset(dict(da=da)) - >>> ds + Reduce this Dataset's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : Dataset + New Dataset with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + Dataset.cumprod + Dataset.cumulative + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> ds = xr.Dataset(dict(da=da)) + >>> ds Size: 120B Dimensions: (time: 6) Coordinates: @@ -6834,21 +6599,21 @@ def cumprod( Data variables: da (time) float64 48B 1.0 2.0 3.0 0.0 2.0 nan - >>> ds.resample(time="3ME").cumprod() + >>> ds.resample(time="3ME").cumprod() Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: da (time) float64 48B 1.0 2.0 6.0 0.0 2.0 2.0 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> ds.resample(time="3ME").cumprod(skipna=False) - Size: 48B - Dimensions: (time: 6) - Dimensions without coordinates: time - Data variables: - da (time) float64 48B 1.0 2.0 6.0 0.0 2.0 nan + >>> ds.resample(time="3ME").cumprod(skipna=False) + Size: 48B + Dimensions: (time: 6) + Dimensions without coordinates: time + Data variables: + da (time) float64 48B 1.0 2.0 6.0 0.0 2.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -6890,69 +6655,66 @@ def count( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - DataArray.count - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + DataArray.count + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").count() - Size: 24B - array([1, 2, 2]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' + >>> da.groupby("labels").count() + Size: 24B + array([1, 2, 2]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6982,69 +6744,66 @@ def all( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - DataArray.all - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + DataArray.all + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 6B array([ True, True, True, True, True, False]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").all() - Size: 3B - array([False, True, True]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' + >>> da.groupby("labels").all() + Size: 3B + array([False, True, True]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7074,69 +6833,66 @@ def any( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - DataArray.any - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + DataArray.any + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 6B array([ True, True, True, True, True, False]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").any() - Size: 3B - array([ True, True, True]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' + >>> da.groupby("labels").any() + Size: 3B + array([ True, True, True]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7167,82 +6923,79 @@ def max( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - DataArray.max - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + DataArray.max + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").max() + >>> da.groupby("labels").max() Size: 24B array([1., 2., 3.]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.groupby("labels").max(skipna=False) - Size: 24B - array([nan, 2., 3.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' + >>> da.groupby("labels").max(skipna=False) + Size: 24B + array([nan, 2., 3.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7275,82 +7028,79 @@ def min( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - DataArray.min - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + DataArray.min + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").min() + >>> da.groupby("labels").min() Size: 24B array([1., 2., 0.]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.groupby("labels").min(skipna=False) - Size: 24B - array([nan, 2., 0.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' + >>> da.groupby("labels").min(skipna=False) + Size: 24B + array([nan, 2., 0.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7383,84 +7133,79 @@ def mean( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - DataArray.mean - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + DataArray.mean + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").mean() + >>> da.groupby("labels").mean() Size: 24B array([1. , 2. , 1.5]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.groupby("labels").mean(skipna=False) - Size: 24B - array([nan, 2. , 1.5]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' + >>> da.groupby("labels").mean(skipna=False) + Size: 24B + array([nan, 2. , 1.5]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7494,98 +7239,95 @@ def prod( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - DataArray.prod - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + DataArray.prod + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").prod() + >>> da.groupby("labels").prod() Size: 24B array([1., 4., 0.]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.groupby("labels").prod(skipna=False) + >>> da.groupby("labels").prod(skipna=False) Size: 24B array([nan, 4., 0.]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> da.groupby("labels").prod(skipna=True, min_count=2) - Size: 24B - array([nan, 4., 0.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' + >>> da.groupby("labels").prod(skipna=True, min_count=2) + Size: 24B + array([nan, 4., 0.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7621,98 +7363,95 @@ def sum( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - DataArray.sum - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + DataArray.sum + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").sum() + >>> da.groupby("labels").sum() Size: 24B array([1., 4., 3.]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.groupby("labels").sum(skipna=False) + >>> da.groupby("labels").sum(skipna=False) Size: 24B array([nan, 4., 3.]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> da.groupby("labels").sum(skipna=True, min_count=2) - Size: 24B - array([nan, 4., 3.]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' + >>> da.groupby("labels").sum(skipna=True, min_count=2) + Size: 24B + array([nan, 4., 3.]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7748,95 +7487,92 @@ def std( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - DataArray.std - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + DataArray.std + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").std() + >>> da.groupby("labels").std() Size: 24B array([0. , 0. , 1.5]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.groupby("labels").std(skipna=False) + >>> da.groupby("labels").std(skipna=False) Size: 24B array([nan, 0. , 1.5]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> da.groupby("labels").std(skipna=True, ddof=1) - Size: 24B - array([ nan, 0. , 2.12132034]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' + >>> da.groupby("labels").std(skipna=True, ddof=1) + Size: 24B + array([ nan, 0. , 2.12132034]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7872,95 +7608,92 @@ def var( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - DataArray.var - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + DataArray.var + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").var() + >>> da.groupby("labels").var() Size: 24B array([0. , 0. , 2.25]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.groupby("labels").var(skipna=False) + >>> da.groupby("labels").var(skipna=False) Size: 24B array([ nan, 0. , 2.25]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> da.groupby("labels").var(skipna=True, ddof=1) - Size: 24B - array([nan, 0. , 4.5]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' + >>> da.groupby("labels").var(skipna=True, ddof=1) + Size: 24B + array([nan, 0. , 4.5]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -7995,84 +7728,81 @@ def median( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - DataArray.median - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + DataArray.median + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").median() + >>> da.groupby("labels").median() Size: 24B array([1. , 2. , 1.5]) Coordinates: * labels (labels) object 24B 'a' 'b' 'c' - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.groupby("labels").median(skipna=False) - Size: 24B - array([nan, 2. , 1.5]) - Coordinates: - * labels (labels) object 24B 'a' 'b' 'c' + >>> da.groupby("labels").median(skipna=False) + Size: 24B + array([nan, 2. , 1.5]) + Coordinates: + * labels (labels) object 24B 'a' 'b' 'c' """ return self.reduce( duck_array_ops.median, @@ -8091,91 +7821,88 @@ def cumsum( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - DataArray.cumsum - DataArray.cumulative - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + DataArray.cumsum + DataArray.cumulative + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").cumsum() + >>> da.groupby("labels").cumsum() Size: 48B array([1., 2., 3., 3., 4., 1.]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").cumsum(skipna=False) - Size: 48B - array([ 1., 2., 3., 3., 4., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").cumsum(skipna=False) + Size: 48B + array([ 1., 2., 3., 3., 4., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) DataArray: """ - Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - DataArray.cumprod - DataArray.cumulative - :ref:`groupby` - User guide on groupby operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up groupby computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the GroupBy dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + DataArray.cumprod + DataArray.cumulative + :ref:`groupby` + User guide on groupby operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up groupby computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").cumprod() + >>> da.groupby("labels").cumprod() Size: 48B array([1., 2., 3., 0., 4., 1.]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.groupby("labels").cumprod(skipna=False) - Size: 48B - array([ 1., 2., 3., 0., 4., nan]) - Coordinates: - * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").cumprod(skipna=False) + Size: 48B + array([ 1., 2., 3., 0., 4., nan]) + Coordinates: + * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 + labels (time) DataArray: """ - Reduce this DataArray's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - DataArray.count - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + DataArray.count + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").count() - Size: 24B - array([1, 3, 1]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + >>> da.resample(time="3ME").count() + Size: 24B + array([1, 3, 1]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8411,69 +8132,66 @@ def all( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - DataArray.all - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + DataArray.all + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 6B array([ True, True, True, True, True, False]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").all() - Size: 3B - array([ True, True, False]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + >>> da.resample(time="3ME").all() + Size: 3B + array([ True, True, False]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8503,69 +8221,66 @@ def any( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - DataArray.any - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([True, True, True, True, True, False], dtype=bool), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + DataArray.any + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([True, True, True, True, True, False], dtype=bool), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 6B array([ True, True, True, True, True, False]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").any() - Size: 3B - array([ True, True, True]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + >>> da.resample(time="3ME").any() + Size: 3B + array([ True, True, True]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8596,82 +8311,79 @@ def max( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - DataArray.max - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + DataArray.max + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").max() + >>> da.resample(time="3ME").max() Size: 24B array([1., 3., 2.]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.resample(time="3ME").max(skipna=False) - Size: 24B - array([ 1., 3., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + >>> da.resample(time="3ME").max(skipna=False) + Size: 24B + array([ 1., 3., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8704,82 +8416,79 @@ def min( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - DataArray.min - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + DataArray.min + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").min() + >>> da.resample(time="3ME").min() Size: 24B array([1., 0., 2.]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.resample(time="3ME").min(skipna=False) - Size: 24B - array([ 1., 0., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + >>> da.resample(time="3ME").min(skipna=False) + Size: 24B + array([ 1., 0., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8812,84 +8521,79 @@ def mean( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - DataArray.mean - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + DataArray.mean + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").mean() + >>> da.resample(time="3ME").mean() Size: 24B array([1. , 1.66666667, 2. ]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.resample(time="3ME").mean(skipna=False) - Size: 24B - array([1. , 1.66666667, nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + >>> da.resample(time="3ME").mean(skipna=False) + Size: 24B + array([1. , 1.66666667, nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -8923,98 +8627,95 @@ def prod( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - DataArray.prod - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + DataArray.prod + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").prod() + >>> da.resample(time="3ME").prod() Size: 24B array([1., 0., 2.]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.resample(time="3ME").prod(skipna=False) + >>> da.resample(time="3ME").prod(skipna=False) Size: 24B array([ 1., 0., nan]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> da.resample(time="3ME").prod(skipna=True, min_count=2) - Size: 24B - array([nan, 0., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + >>> da.resample(time="3ME").prod(skipna=True, min_count=2) + Size: 24B + array([nan, 0., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -9050,98 +8751,95 @@ def sum( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - DataArray.sum - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + DataArray.sum + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").sum() + >>> da.resample(time="3ME").sum() Size: 24B array([1., 5., 2.]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.resample(time="3ME").sum(skipna=False) + >>> da.resample(time="3ME").sum(skipna=False) Size: 24B array([ 1., 5., nan]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> da.resample(time="3ME").sum(skipna=True, min_count=2) - Size: 24B - array([nan, 5., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + >>> da.resample(time="3ME").sum(skipna=True, min_count=2) + Size: 24B + array([nan, 5., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -9177,95 +8875,92 @@ def std( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - DataArray.std - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + DataArray.std + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").std() + >>> da.resample(time="3ME").std() Size: 24B array([0. , 1.24721913, 0. ]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.resample(time="3ME").std(skipna=False) + >>> da.resample(time="3ME").std(skipna=False) Size: 24B array([0. , 1.24721913, nan]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> da.resample(time="3ME").std(skipna=True, ddof=1) - Size: 24B - array([ nan, 1.52752523, nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + >>> da.resample(time="3ME").std(skipna=True, ddof=1) + Size: 24B + array([ nan, 1.52752523, nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -9301,95 +8996,92 @@ def var( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - DataArray.var - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + DataArray.var + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").var() + >>> da.resample(time="3ME").var() Size: 24B array([0. , 1.55555556, 0. ]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.resample(time="3ME").var(skipna=False) + >>> da.resample(time="3ME").var(skipna=False) Size: 24B array([0. , 1.55555556, nan]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> da.resample(time="3ME").var(skipna=True, ddof=1) - Size: 24B - array([ nan, 2.33333333, nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + >>> da.resample(time="3ME").var(skipna=True, ddof=1) + Size: 24B + array([ nan, 2.33333333, nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -9424,84 +9116,81 @@ def median( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - DataArray.median - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + DataArray.median + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").median() + >>> da.resample(time="3ME").median() Size: 24B array([1., 2., 2.]) Coordinates: * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> da.resample(time="3ME").median(skipna=False) - Size: 24B - array([ 1., 2., nan]) - Coordinates: - * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 + >>> da.resample(time="3ME").median(skipna=False) + Size: 24B + array([ 1., 2., nan]) + Coordinates: + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ return self.reduce( duck_array_ops.median, @@ -9520,91 +9209,88 @@ def cumsum( **kwargs: Any, ) -> DataArray: """ - Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - DataArray.cumsum - DataArray.cumulative - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + DataArray.cumsum + DataArray.cumulative + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").cumsum() + >>> da.resample(time="3ME").cumsum() Size: 48B array([1., 2., 5., 5., 2., 2.]) Coordinates: labels (time) >> da.resample(time="3ME").cumsum(skipna=False) - Size: 48B - array([ 1., 2., 5., 5., 2., nan]) - Coordinates: - labels (time) >> da.resample(time="3ME").cumsum(skipna=False) + Size: 48B + array([ 1., 2., 5., 5., 2., nan]) + Coordinates: + labels (time) DataArray: """ - Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. - If "...", will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - keep_attrs : bool or None, optional - If True, ``attrs`` will be copied from the original - object to the new one. If False, the new object will be - returned without attributes. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : DataArray - New DataArray with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - DataArray.cumprod - DataArray.cumulative - :ref:`resampling` - User guide on resampling operations. - - Notes - ----- - Use the ``flox`` package to significantly speed up resampling computations, - especially with dask arrays. Xarray will use flox by default if installed. - Pass flox-specific keyword arguments in ``**kwargs``. - See the `flox documentation `_ for more. - - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> da = xr.DataArray( - ... np.array([1, 2, 3, 0, 2, np.nan]), - ... dims="time", - ... coords=dict( - ... time=( - ... "time", - ... pd.date_range("2001-01-01", freq="ME", periods=6), - ... ), - ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), - ... ), - ... ) - >>> da + Reduce this DataArray's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If None, will reduce over the Resample dimensions. + If "...", will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + keep_attrs : bool or None, optional + If True, ``attrs`` will be copied from the original + object to the new one. If False, the new object will be + returned without attributes. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : DataArray + New DataArray with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + DataArray.cumprod + DataArray.cumulative + :ref:`resampling` + User guide on resampling operations. + + Notes + ----- + Use the ``flox`` package to significantly speed up resampling computations, + especially with dask arrays. Xarray will use flox by default if installed. + Pass flox-specific keyword arguments in ``**kwargs``. + See the `flox documentation `_ for more. + + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> da = xr.DataArray( + ... np.array([1, 2, 3, 0, 2, np.nan]), + ... dims="time", + ... coords=dict( + ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), + ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), + ... ), + ... ) + >>> da Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: * time (time) datetime64[ns] 48B 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) >> da.resample(time="3ME").cumprod() + >>> da.resample(time="3ME").cumprod() Size: 48B array([1., 2., 6., 0., 2., 2.]) Coordinates: labels (time) >> da.resample(time="3ME").cumprod(skipna=False) - Size: 48B - array([ 1., 2., 6., 0., 2., nan]) - Coordinates: - labels (time) >> da.resample(time="3ME").cumprod(skipna=False) + Size: 48B + array([ 1., 2., 6., 0., 2., nan]) + Coordinates: + labels (time) Date: Fri, 12 Dec 2025 23:15:31 +1100 Subject: [PATCH 4/4] fix doctests and min version tests --- xarray/namedarray/_aggregations.py | 1191 ++++++++++++++-------------- xarray/tests/test_backends.py | 3 +- 2 files changed, 595 insertions(+), 599 deletions(-) diff --git a/xarray/namedarray/_aggregations.py b/xarray/namedarray/_aggregations.py index e2717628910..c5726ef9251 100644 --- a/xarray/namedarray/_aggregations.py +++ b/xarray/namedarray/_aggregations.py @@ -1,4 +1,5 @@ """Mixin classes with reduction operations.""" + # This file was generated using xarray.util.generate_aggregations. Do not edit manually. from __future__ import annotations @@ -30,44 +31,44 @@ def count( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``count`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``count`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``count`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - pandas.DataFrame.count - dask.dataframe.DataFrame.count - Dataset.count - DataArray.count - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na + Reduce this NamedArray's data by applying ``count`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``count``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``count`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``count`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + pandas.DataFrame.count + dask.dataframe.DataFrame.count + Dataset.count + DataArray.count + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na Size: 48B array([ 1., 2., 3., 0., 2., nan]) - >>> na.count() - Size: 8B - array(5) + >>> na.count() + Size: 8B + array(5) """ return self.reduce( duck_array_ops.count, @@ -81,46 +82,46 @@ def all( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``all`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``all`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``all`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.all - dask.array.all - Dataset.all - DataArray.all - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray( - ... "x", np.array([True, True, True, True, True, False], dtype=bool) - ... ) - >>> na + Reduce this NamedArray's data by applying ``all`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``all``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``all`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``all`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.all + dask.array.all + Dataset.all + DataArray.all + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray( + ... "x", np.array([True, True, True, True, True, False], dtype=bool) + ... ) + >>> na Size: 6B array([ True, True, True, True, True, False]) - >>> na.all() - Size: 1B - array(False) + >>> na.all() + Size: 1B + array(False) """ return self.reduce( duck_array_ops.array_all, @@ -134,46 +135,46 @@ def any( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``any`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``any`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``any`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.any - dask.array.any - Dataset.any - DataArray.any - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray( - ... "x", np.array([True, True, True, True, True, False], dtype=bool) - ... ) - >>> na + Reduce this NamedArray's data by applying ``any`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``any``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``any`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``any`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.any + dask.array.any + Dataset.any + DataArray.any + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray( + ... "x", np.array([True, True, True, True, True, False], dtype=bool) + ... ) + >>> na Size: 6B array([ True, True, True, True, True, False]) - >>> na.any() - Size: 1B - array(True) + >>> na.any() + Size: 1B + array(True) """ return self.reduce( duck_array_ops.array_any, @@ -189,55 +190,55 @@ def max( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``max`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``max`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``max`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.max - dask.array.max - Dataset.max - DataArray.max - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na + Reduce this NamedArray's data by applying ``max`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``max``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``max`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``max`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.max + dask.array.max + Dataset.max + DataArray.max + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na Size: 48B array([ 1., 2., 3., 0., 2., nan]) - >>> na.max() + >>> na.max() Size: 8B array(3.) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> na.max(skipna=False) - Size: 8B - array(nan) + >>> na.max(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.max, @@ -254,55 +255,55 @@ def min( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``min`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``min`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``min`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.min - dask.array.min - Dataset.min - DataArray.min - :ref:`agg` - User guide on reduction or aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na + Reduce this NamedArray's data by applying ``min`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``min``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``min`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``min`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.min + dask.array.min + Dataset.min + DataArray.min + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na Size: 48B array([ 1., 2., 3., 0., 2., nan]) - >>> na.min() + >>> na.min() Size: 8B array(0.) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> na.min(skipna=False) - Size: 8B - array(nan) + >>> na.min(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.min, @@ -319,59 +320,55 @@ def mean( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``mean`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``mean`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``mean`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.mean - dask.array.mean - Dataset.mean - DataArray.mean - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na + Reduce this NamedArray's data by applying ``mean`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``mean``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``mean`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``mean`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.mean + dask.array.mean + Dataset.mean + DataArray.mean + :ref:`agg` + User guide on reduction or aggregation operations. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na Size: 48B array([ 1., 2., 3., 0., 2., nan]) - >>> na.mean() + >>> na.mean() Size: 8B array(1.6) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> na.mean(skipna=False) - Size: 8B - array(nan) + >>> na.mean(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.mean, @@ -389,71 +386,71 @@ def prod( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``prod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``prod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``prod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.prod - dask.array.prod - Dataset.prod - DataArray.prod - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na + Reduce this NamedArray's data by applying ``prod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``prod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``prod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``prod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.prod + dask.array.prod + Dataset.prod + DataArray.prod + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na Size: 48B array([ 1., 2., 3., 0., 2., nan]) - >>> na.prod() + >>> na.prod() Size: 8B array(0.) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> na.prod(skipna=False) + >>> na.prod(skipna=False) Size: 8B array(nan) - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> na.prod(skipna=True, min_count=2) - Size: 8B - array(0.) + >>> na.prod(skipna=True, min_count=2) + Size: 8B + array(0.) """ return self.reduce( duck_array_ops.prod, @@ -472,71 +469,71 @@ def sum( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``sum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - min_count : int or None, optional - The required number of valid values to perform the operation. If - fewer than min_count non-NA values are present the result will be - NA. Only used if skipna is set to True or defaults to True for the - array's dtype. Changed in version 0.17.0: if specified on an integer - array and skipna=True, the result will be a float array. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``sum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``sum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.sum - dask.array.sum - Dataset.sum - DataArray.sum - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na + Reduce this NamedArray's data by applying ``sum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``sum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + min_count : int or None, optional + The required number of valid values to perform the operation. If + fewer than min_count non-NA values are present the result will be + NA. Only used if skipna is set to True or defaults to True for the + array's dtype. Changed in version 0.17.0: if specified on an integer + array and skipna=True, the result will be a float array. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``sum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``sum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.sum + dask.array.sum + Dataset.sum + DataArray.sum + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na Size: 48B array([ 1., 2., 3., 0., 2., nan]) - >>> na.sum() + >>> na.sum() Size: 8B array(8.) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> na.sum(skipna=False) + >>> na.sum(skipna=False) Size: 8B array(nan) - Specify ``min_count`` for finer control over when NaNs are ignored. + Specify ``min_count`` for finer control over when NaNs are ignored. - >>> na.sum(skipna=True, min_count=2) - Size: 8B - array(8.) + >>> na.sum(skipna=True, min_count=2) + Size: 8B + array(8.) """ return self.reduce( duck_array_ops.sum, @@ -555,68 +552,68 @@ def std( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``std`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``std`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``std`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.std - dask.array.std - Dataset.std - DataArray.std - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na + Reduce this NamedArray's data by applying ``std`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``std``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``std`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``std`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.std + dask.array.std + Dataset.std + DataArray.std + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na Size: 48B array([ 1., 2., 3., 0., 2., nan]) - >>> na.std() + >>> na.std() Size: 8B array(1.0198039) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> na.std(skipna=False) + >>> na.std(skipna=False) Size: 8B array(nan) - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> na.std(skipna=True, ddof=1) - Size: 8B - array(1.14017543) + >>> na.std(skipna=True, ddof=1) + Size: 8B + array(1.14017543) """ return self.reduce( duck_array_ops.std, @@ -635,68 +632,68 @@ def var( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``var`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - ddof : int, default: 0 - “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, - where ``N`` represents the number of elements. - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``var`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``var`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.var - dask.array.var - Dataset.var - DataArray.var - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na + Reduce this NamedArray's data by applying ``var`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``var``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + ddof : int, default: 0 + “Delta Degrees of Freedom”: the divisor used in the calculation is ``N - ddof``, + where ``N`` represents the number of elements. + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``var`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``var`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.var + dask.array.var + Dataset.var + DataArray.var + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na Size: 48B array([ 1., 2., 3., 0., 2., nan]) - >>> na.var() + >>> na.var() Size: 8B array(1.04) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> na.var(skipna=False) + >>> na.var(skipna=False) Size: 8B array(nan) - Specify ``ddof=1`` for an unbiased estimate. + Specify ``ddof=1`` for an unbiased estimate. - >>> na.var(skipna=True, ddof=1) - Size: 8B - array(1.3) + >>> na.var(skipna=True, ddof=1) + Size: 8B + array(1.3) """ return self.reduce( duck_array_ops.var, @@ -714,59 +711,59 @@ def median( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``median`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``median`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``median`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.median - dask.array.median - Dataset.median - DataArray.median - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na + Reduce this NamedArray's data by applying ``median`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``median``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``median`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``median`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.median + dask.array.median + Dataset.median + DataArray.median + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na Size: 48B array([ 1., 2., 3., 0., 2., nan]) - >>> na.median() + >>> na.median() Size: 8B array(2.) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> na.median(skipna=False) - Size: 8B - array(nan) + >>> na.median(skipna=False) + Size: 8B + array(nan) """ return self.reduce( duck_array_ops.median, @@ -783,64 +780,64 @@ def cumsum( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``cumsum`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumsum`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``cumsum`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumsum - dask.array.cumsum - Dataset.cumsum - DataArray.cumsum - NamedArray.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na + Reduce this NamedArray's data by applying ``cumsum`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumsum``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumsum`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``cumsum`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumsum + dask.array.cumsum + Dataset.cumsum + DataArray.cumsum + NamedArray.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na Size: 48B array([ 1., 2., 3., 0., 2., nan]) - >>> na.cumsum() + >>> na.cumsum() Size: 48B array([1., 3., 6., 6., 8., 8.]) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> na.cumsum(skipna=False) - Size: 48B - array([ 1., 3., 6., 6., 8., nan]) + >>> na.cumsum(skipna=False) + Size: 48B + array([ 1., 3., 6., 6., 8., nan]) """ return self.reduce( duck_array_ops.cumsum, @@ -857,64 +854,64 @@ def cumprod( **kwargs: Any, ) -> Self: """ - Reduce this NamedArray's data by applying ``cumprod`` along some dimension(s). - - Parameters - ---------- - dim : str, Iterable of Hashable, "..." or None, default: None - Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` - or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. - skipna : bool or None, optional - If True, skip missing values (as marked by NaN). By default, only - skips missing values for float dtypes; other dtypes either do not - have a sentinel missing value (int) or ``skipna=True`` has not been - implemented (object, datetime64 or timedelta64). - **kwargs : Any - Additional keyword arguments passed on to the appropriate array - function for calculating ``cumprod`` on this object's data. - These could include dask-specific kwargs like ``split_every``. - - Returns - ------- - reduced : NamedArray - New NamedArray with ``cumprod`` applied to its data and the - indicated dimension(s) removed - - See Also - -------- - numpy.cumprod - dask.array.cumprod - Dataset.cumprod - DataArray.cumprod - NamedArray.cumulative - :ref:`agg` - User guide on reduction or aggregation operations. - - Notes - ----- - Non-numeric variables will be removed prior to reducing. datetime64 and timedelta64 dtypes are treated as numeric for aggregation operations. - - Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) - and better supported. ``cumsum`` and ``cumprod`` may be deprecated - in the future. - - Examples - -------- - >>> from xarray.namedarray.core import NamedArray - >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) - >>> na + Reduce this NamedArray's data by applying ``cumprod`` along some dimension(s). + + Parameters + ---------- + dim : str, Iterable of Hashable, "..." or None, default: None + Name of dimension[s] along which to apply ``cumprod``. For e.g. ``dim="x"`` + or ``dim=["x", "y"]``. If "..." or None, will reduce over all dimensions. + skipna : bool or None, optional + If True, skip missing values (as marked by NaN). By default, only + skips missing values for float dtypes; other dtypes either do not + have a sentinel missing value (int) or ``skipna=True`` has not been + implemented (object, datetime64 or timedelta64). + **kwargs : Any + Additional keyword arguments passed on to the appropriate array + function for calculating ``cumprod`` on this object's data. + These could include dask-specific kwargs like ``split_every``. + + Returns + ------- + reduced : NamedArray + New NamedArray with ``cumprod`` applied to its data and the + indicated dimension(s) removed + + See Also + -------- + numpy.cumprod + dask.array.cumprod + Dataset.cumprod + DataArray.cumprod + NamedArray.cumulative + :ref:`agg` + User guide on reduction or aggregation operations. + + Notes + ----- + Non-numeric variables will be removed prior to reducing. + + Note that the methods on the ``cumulative`` method are more performant (with numbagg installed) + and better supported. ``cumsum`` and ``cumprod`` may be deprecated + in the future. + + Examples + -------- + >>> from xarray.namedarray.core import NamedArray + >>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan])) + >>> na Size: 48B array([ 1., 2., 3., 0., 2., nan]) - >>> na.cumprod() + >>> na.cumprod() Size: 48B array([1., 2., 6., 0., 0., 0.]) - Use ``skipna`` to control whether NaNs are ignored. + Use ``skipna`` to control whether NaNs are ignored. - >>> na.cumprod(skipna=False) - Size: 48B - array([ 1., 2., 6., 0., 0., nan]) + >>> na.cumprod(skipna=False) + Size: 48B + array([ 1., 2., 6., 0., 0., nan]) """ return self.reduce( duck_array_ops.cumprod, diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 8135191c421..be7ac06c068 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -4417,8 +4417,7 @@ def _strip_zarr_2(self, ds_path, stripped_ds_path): @pytest.mark.parametrize("consolidated", [True, False]) def test_default_dims(self, consolidated): - zarr_format = zarr.config.get("default_zarr_format") - print(zarr_format) + zarr_format = zarr.config.get("default_zarr_format") if has_zarr_v3 else 2 # Create example data that can be read without dimension name metadata da_a = xr.DataArray(np.arange(3 * 18).reshape(3, 18), dims=["label", "z"]) da_b = xr.DataArray(np.arange(3), dims="label")