Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cross-links to API docstring from tutorial and user-guide #8311

Merged
merged 9 commits into from
Nov 5, 2023
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
"sparse": ("https://sparse.pydata.org/en/latest/", None),
"cubed": ("https://tom-e-white.com/cubed/", None),
"datatree": ("https://xarray-datatree.readthedocs.io/en/latest/", None),
"xarray-tutorial": ("https://tutorial.xarray.dev/", None),
# "opt_einsum": ("https://dgasmith.github.io/opt_einsum/", None),
}

Expand Down
4 changes: 4 additions & 0 deletions xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,13 @@ def apply_ufunc(
numba.guvectorize
dask.array.apply_gufunc
xarray.map_blocks

:ref:`dask.automatic-parallelization`
User guide describing :py:func:`apply_ufunc` and :py:func:`map_blocks`.

:doc:`xarray-tutorial:advanced/apply_ufunc/apply_ufunc`
Advanced Tutorial on applying numpy function using :py:func:`apply_ufunc`

References
----------
.. [1] https://numpy.org/doc/stable/reference/ufuncs.html
Expand Down
45 changes: 45 additions & 0 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,12 @@ def isel(
Dataset.isel
DataArray.sel

:doc:`xarray-tutorial:intermediate/indexing/indexing`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:( This seems to have messed up some formatting though:
image

while on main
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be valid, though. So we might need to fix napoleon to allow this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it appears we had a similar issue more than two years ago when we first introduced :doc: links to See Also (see #5176), where we concluded that this is a bug in napoleon (nobody got around to reporting / fixing that since then, though).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK well this is an improvement in any case. Merging.

Tutorial material on indexing with Xarray objects

:doc:`xarray-tutorial:fundamentals/02.1_indexing_Basic`
Tutorial material on basics of indexing

Examples
--------
>>> da = xr.DataArray(np.arange(25).reshape(5, 5), dims=("x", "y"))
Expand Down Expand Up @@ -1563,6 +1569,12 @@ def sel(
Dataset.sel
DataArray.isel

:doc:`xarray-tutorial:intermediate/indexing/indexing`
Tutorial material on indexing with Xarray objects

:doc:`xarray-tutorial:fundamentals/02.1_indexing_Basic`
Tutorial material on basics of indexing

Examples
--------
>>> da = xr.DataArray(
Expand Down Expand Up @@ -2196,6 +2208,9 @@ def interp(
scipy.interpolate.interp1d
scipy.interpolate.interpn

:doc:`xarray-tutorial:fundamentals/02.2_manipulating_dimensions`
Tutorial material on manipulating data resolution using :py:func:`~xarray.DataArray.interp`

Examples
--------
>>> da = xr.DataArray(
Expand Down Expand Up @@ -5461,6 +5476,9 @@ def map_blocks(
dask.array.map_blocks, xarray.apply_ufunc, xarray.Dataset.map_blocks
xarray.DataArray.map_blocks

:doc:`xarray-tutorial:advanced/map_blocks/map_blocks`
Advanced Tutorial on map_blocks with dask

Examples
--------
Calculate an anomaly from climatology using ``.groupby()``. Using
Expand Down Expand Up @@ -6676,10 +6694,20 @@ def groupby(
--------
:ref:`groupby`
Users guide explanation of how to group and bin data.

:doc:`xarray-tutorial:intermediate/01-high-level-computation-patterns`
Tutorial on :py:func:`~xarray.DataArray.Groupby` for windowed computation

:doc:`xarray-tutorial:fundamentals/03.2_groupby_with_xarray`
Tutorial on :py:func:`~xarray.DataArray.Groupby` demonstrating reductions, transformation and comparison with :py:func:`~xarray.DataArray.resample`

DataArray.groupby_bins
Dataset.groupby
core.groupby.DataArrayGroupBy
DataArray.coarsen
pandas.DataFrame.groupby
Dataset.resample
DataArray.resample
"""
from xarray.core.groupby import (
DataArrayGroupBy,
Expand Down Expand Up @@ -6814,6 +6842,13 @@ def weighted(self, weights: DataArray) -> DataArrayWeighted:
See Also
--------
Dataset.weighted

:ref:`comput.weighted`
User guide on weighted array reduction using :py:func:`~xarray.DataArray.weighted`

:doc:`xarray-tutorial:fundamentals/03.4_weighted`
Tutorial on Weighted Reduction using :py:func:`~xarray.DataArray.weighted`

"""
from xarray.core.weighted import DataArrayWeighted

Expand Down Expand Up @@ -6955,6 +6990,16 @@ def coarsen(
--------
core.rolling.DataArrayCoarsen
Dataset.coarsen

:ref:`reshape.coarsen`
User guide describing :py:func:`~xarray.DataArray.coarsen`

:ref:`compute.coarsen`
User guide on block arrgragation :py:func:`~xarray.DataArray.coarsen`

:doc:`xarray-tutorial:fundamentals/03.3_windowed`
Tutorial on windowed computation using :py:func:`~xarray.DataArray.coarsen`

"""
from xarray.core.rolling import DataArrayCoarsen

Expand Down
46 changes: 46 additions & 0 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2902,6 +2902,13 @@ def isel(
--------
Dataset.sel
DataArray.isel

:doc:`xarray-tutorial:intermediate/indexing/indexing`
Tutorial material on indexing with Xarray objects

:doc:`xarray-tutorial:fundamentals/02.1_indexing_Basic`
Tutorial material on basics of indexing

"""
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "isel")
if any(is_fancy_indexer(idx) for idx in indexers.values()):
Expand Down Expand Up @@ -3049,6 +3056,13 @@ def sel(
--------
Dataset.isel
DataArray.sel

:doc:`xarray-tutorial:intermediate/indexing/indexing`
Tutorial material on indexing with Xarray objects

:doc:`xarray-tutorial:fundamentals/02.1_indexing_Basic`
Tutorial material on basics of indexing

"""
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "sel")
query_results = map_index_queries(
Expand Down Expand Up @@ -3801,6 +3815,9 @@ def interp(
scipy.interpolate.interp1d
scipy.interpolate.interpn

:doc:`xarray-tutorial:fundamentals/02.2_manipulating_dimensions`
Tutorial material on manipulating data resolution using :py:func:`~xarray.Dataset.interp`

Examples
--------
>>> ds = xr.Dataset(
Expand Down Expand Up @@ -8650,6 +8667,10 @@ def map_blocks(
dask.array.map_blocks, xarray.apply_ufunc, xarray.Dataset.map_blocks
xarray.DataArray.map_blocks

:doc:`xarray-tutorial:advanced/map_blocks/map_blocks`
Advanced Tutorial on map_blocks with dask


Examples
--------
Calculate an anomaly from climatology using ``.groupby()``. Using
Expand Down Expand Up @@ -10035,10 +10056,18 @@ def groupby(
--------
:ref:`groupby`
Users guide explanation of how to group and bin data.

:doc:`xarray-tutorial:intermediate/01-high-level-computation-patterns`
Tutorial on :py:func:`~xarray.Dataset.Groupby` for windowed computation.

:doc:`xarray-tutorial:fundamentals/03.2_groupby_with_xarray`
Tutorial on :py:func:`~xarray.Dataset.Groupby` demonstrating reductions, transformation and comparision with :py:func:`~xarray.Dataset.resample`.

Dataset.groupby_bins
DataArray.groupby
core.groupby.DatasetGroupBy
pandas.DataFrame.groupby
Dataset.coarsen
Dataset.resample
DataArray.resample
"""
Expand Down Expand Up @@ -10176,6 +10205,13 @@ def weighted(self, weights: DataArray) -> DatasetWeighted:
See Also
--------
DataArray.weighted

:ref:`comput.weighted`
User guide on weighted array reduction using :py:func:`~xarray.Dataset.weighted`

:doc:`xarray-tutorial:fundamentals/03.4_weighted`
Tutorial on Weighted Reduction using :py:func:`~xarray.Dataset.weighted`

"""
from xarray.core.weighted import DatasetWeighted

Expand Down Expand Up @@ -10252,6 +10288,16 @@ def coarsen(
--------
core.rolling.DatasetCoarsen
DataArray.coarsen

:ref:`reshape.coarsen`
User guide describing :py:func:`~xarray.Dataset.coarsen`

:ref:`compute.coarsen`
User guide on block arrgragation :py:func:`~xarray.Dataset.coarsen`

:doc:`xarray-tutorial:fundamentals/03.3_windowed`
Tutorial on windowed computation using :py:func:`~xarray.Dataset.coarsen`

"""
from xarray.core.rolling import DatasetCoarsen

Expand Down
1 change: 1 addition & 0 deletions xarray/core/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ def __init__(
Returns
-------
coarsen

"""
self.obj = obj
self.windows = windows
Expand Down
Loading