From 53db66c3e994ba530c565604644464da8eee6702 Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 30 Oct 2019 15:58:56 +0100 Subject: [PATCH 1/6] rename the coord parameter of `Dataset.integrate` --- xarray/core/dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 05d9772cb7a..e50861755a3 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 From e365a893d3b6145161f0f711bfaf831569c47734 Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 30 Oct 2019 16:09:05 +0100 Subject: [PATCH 2/6] add an example to `Dataset.integrate` --- xarray/core/dataset.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index e50861755a3..c9384b7a41c 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -5180,6 +5180,25 @@ 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", [10, 11, 12, 13])}, + ... ) + >>> ds.integrate("x") + + Dimensions: () + Data variables: + a float64 19.5 + b float64 3.5 + >>> ds.integrate("y") + + Dimensions: () + Data variables: + a float64 19.5 + b float64 3.5 """ if not isinstance(coord, (list, tuple)): coord = (coord,) From ca5496f59f28d60de3f654b7f05cb19c49e2a645 Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 30 Oct 2019 16:10:38 +0100 Subject: [PATCH 3/6] refer to an actual parameter in the note --- xarray/core/dataarray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 2c889f08d45d9c8c107c892441818f98b37213e2 Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 30 Oct 2019 18:08:56 +0100 Subject: [PATCH 4/6] don't just make y the same as x with an offset so now the results are different depending on integration with x or y --- xarray/core/dataset.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index c9384b7a41c..a83020487cf 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -5185,20 +5185,20 @@ def integrate(self, coord, datetime_unit=None): -------- >>> 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", [10, 11, 12, 13])}, + ... coords={"x": [0, 1, 2, 3], "y": ("x", [1, 7, 3, 5])}, ... ) >>> ds.integrate("x") Dimensions: () Data variables: - a float64 19.5 + a float64 16.5 b float64 3.5 >>> ds.integrate("y") Dimensions: () Data variables: - a float64 19.5 - b float64 3.5 + a float64 20.0 + b float64 4.0 """ if not isinstance(coord, (list, tuple)): coord = (coord,) From a8c187477cef308e93a46c485fe7e955d33525d8 Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 30 Oct 2019 18:10:14 +0100 Subject: [PATCH 5/6] show the repr of the example dataset --- xarray/core/dataset.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index a83020487cf..31efcb1d591 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -5187,6 +5187,15 @@ def integrate(self, coord, datetime_unit=None): ... 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: () From 8f3729f7038fd74f18bb1ea8401527eff11f5797 Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 30 Oct 2019 18:22:21 +0100 Subject: [PATCH 6/6] update whats-new.rst --- doc/whats-new.rst | 4 ++++ 1 file changed, 4 insertions(+) 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 ~~~~~~~~~~~~~~~~