Skip to content

Commit c0af5e7

Browse files
keewismax-sixty
authored andcommitted
Fix integrate docs (#3469)
* rename the coord parameter of `Dataset.integrate` * add an example to `Dataset.integrate` * refer to an actual parameter in the note * 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 * show the repr of the example dataset * update whats-new.rst
1 parent 59f88f7 commit c0af5e7

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

doc/whats-new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ Documentation
7474
By `Justus Magin <https://github.com/keewis>`_.
7575
- Update the terminology page to address multidimensional coordinates. (:pull:`3410`)
7676
By `Jon Thielen <https://github.com/jthielen>`_.
77+
- Fix the documentation of :py:meth:`Dataset.integrate` and
78+
:py:meth:`DataArray.integrate` and add an example to
79+
:py:meth:`Dataset.integrate`. (:pull:`3469`)
80+
By `Justus Magin <https://github.com/keewis>`_.
7781

7882
Internal Changes
7983
~~~~~~~~~~~~~~~~

xarray/core/dataarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2995,7 +2995,7 @@ def integrate(
29952995
""" integrate the array with the trapezoidal rule.
29962996
29972997
.. note::
2998-
This feature is limited to simple cartesian geometry, i.e. coord
2998+
This feature is limited to simple cartesian geometry, i.e. dim
29992999
must be one dimensional.
30003000
30013001
Parameters

xarray/core/dataset.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5165,7 +5165,7 @@ def integrate(self, coord, datetime_unit=None):
51655165
51665166
Parameters
51675167
----------
5168-
dim: str, or a sequence of str
5168+
coord: str, or a sequence of str
51695169
Coordinate(s) used for the integration.
51705170
datetime_unit
51715171
Can be specify the unit if datetime coordinate is used. One of
@@ -5180,6 +5180,34 @@ def integrate(self, coord, datetime_unit=None):
51805180
--------
51815181
DataArray.integrate
51825182
numpy.trapz: corresponding numpy function
5183+
5184+
Examples
5185+
--------
5186+
>>> ds = xr.Dataset(
5187+
... data_vars={"a": ("x", [5, 5, 6, 6]), "b": ("x", [1, 2, 1, 0])},
5188+
... coords={"x": [0, 1, 2, 3], "y": ("x", [1, 7, 3, 5])},
5189+
... )
5190+
>>> ds
5191+
<xarray.Dataset>
5192+
Dimensions: (x: 4)
5193+
Coordinates:
5194+
* x (x) int64 0 1 2 3
5195+
y (x) int64 1 7 3 5
5196+
Data variables:
5197+
a (x) int64 5 5 6 6
5198+
b (x) int64 1 2 1 0
5199+
>>> ds.integrate("x")
5200+
<xarray.Dataset>
5201+
Dimensions: ()
5202+
Data variables:
5203+
a float64 16.5
5204+
b float64 3.5
5205+
>>> ds.integrate("y")
5206+
<xarray.Dataset>
5207+
Dimensions: ()
5208+
Data variables:
5209+
a float64 20.0
5210+
b float64 4.0
51835211
"""
51845212
if not isinstance(coord, (list, tuple)):
51855213
coord = (coord,)

0 commit comments

Comments
 (0)