diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 8f98a3860b2..36ba0681ea2 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -74,6 +74,10 @@ Documentation By `Justus Magin `_. - Update the terminology page to address multidimensional coordinates. (:pull:`3410`) By `Jon Thielen `_. +- Fix the documentation of :py:meth:`Dataset.integrate` and + :py:meth:`DataArray.integrate` and add an example to + :py:meth:`Dataset.integrate`. (:pull:`3469`) + By `Justus Magin `_. Internal Changes ~~~~~~~~~~~~~~~~ diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 62890f9cefa..502d88f4f1f 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -2995,7 +2995,7 @@ def integrate( """ integrate the array with the trapezoidal rule. .. note:: - This feature is limited to simple cartesian geometry, i.e. coord + This feature is limited to simple cartesian geometry, i.e. dim must be one dimensional. Parameters diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 05d9772cb7a..31efcb1d591 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -5165,7 +5165,7 @@ def integrate(self, coord, datetime_unit=None): Parameters ---------- - dim: str, or a sequence of str + coord: str, or a sequence of str Coordinate(s) used for the integration. datetime_unit Can be specify the unit if datetime coordinate is used. One of @@ -5180,6 +5180,34 @@ def integrate(self, coord, datetime_unit=None): -------- DataArray.integrate numpy.trapz: corresponding numpy function + + Examples + -------- + >>> ds = xr.Dataset( + ... data_vars={"a": ("x", [5, 5, 6, 6]), "b": ("x", [1, 2, 1, 0])}, + ... coords={"x": [0, 1, 2, 3], "y": ("x", [1, 7, 3, 5])}, + ... ) + >>> ds + + Dimensions: (x: 4) + Coordinates: + * x (x) int64 0 1 2 3 + y (x) int64 1 7 3 5 + Data variables: + a (x) int64 5 5 6 6 + b (x) int64 1 2 1 0 + >>> ds.integrate("x") + + Dimensions: () + Data variables: + a float64 16.5 + b float64 3.5 + >>> ds.integrate("y") + + Dimensions: () + Data variables: + a float64 20.0 + b float64 4.0 """ if not isinstance(coord, (list, tuple)): coord = (coord,)