Skip to content

Commit

Permalink
Fix integrate docs (#3469)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
keewis authored and max-sixty committed Oct 30, 2019
1 parent 59f88f7 commit c0af5e7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Documentation
By `Justus Magin <https://github.com/keewis>`_.
- Update the terminology page to address multidimensional coordinates. (:pull:`3410`)
By `Jon Thielen <https://github.com/jthielen>`_.
- 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 <https://github.com/keewis>`_.

Internal Changes
~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
<xarray.Dataset>
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")
<xarray.Dataset>
Dimensions: ()
Data variables:
a float64 16.5
b float64 3.5
>>> ds.integrate("y")
<xarray.Dataset>
Dimensions: ()
Data variables:
a float64 20.0
b float64 4.0
"""
if not isinstance(coord, (list, tuple)):
coord = (coord,)
Expand Down

0 comments on commit c0af5e7

Please sign in to comment.