Skip to content

Commit c5b90c5

Browse files
saschahofmannkeewispre-commit-ci[bot]max-sixty
authored
Update docstring for compute and persist (#8903)
* Update docstring for compute and persist * Add compute reference to load docstring for dask array * Use new wording for persist Co-authored-by: Justus Magin <keewis@users.noreply.github.com> * Update xarray/core/dataarray.py Co-authored-by: Justus Magin <keewis@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Justus Magin <keewis@users.noreply.github.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add "all" to persist docstring * Apply suggestions from code review Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> --------- Co-authored-by: Justus Magin <keewis@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
1 parent 97d3a3a commit c5b90c5

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

xarray/core/dataarray.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,8 @@ def load(self, **kwargs) -> Self:
11261126
"""Manually trigger loading of this array's data from disk or a
11271127
remote source into memory and return this array.
11281128
1129+
Unlike compute, the original dataset is modified and returned.
1130+
11291131
Normally, it should not be necessary to call this method in user code,
11301132
because all xarray functions should either work on deferred data or
11311133
load data automatically. However, this method can be necessary when
@@ -1148,8 +1150,9 @@ def load(self, **kwargs) -> Self:
11481150

11491151
def compute(self, **kwargs) -> Self:
11501152
"""Manually trigger loading of this array's data from disk or a
1151-
remote source into memory and return a new array. The original is
1152-
left unaltered.
1153+
remote source into memory and return a new array.
1154+
1155+
Unlike load, the original is left unaltered.
11531156
11541157
Normally, it should not be necessary to call this method in user code,
11551158
because all xarray functions should either work on deferred data or
@@ -1161,6 +1164,11 @@ def compute(self, **kwargs) -> Self:
11611164
**kwargs : dict
11621165
Additional keyword arguments passed on to ``dask.compute``.
11631166
1167+
Returns
1168+
-------
1169+
object : DataArray
1170+
New object with the data and all coordinates as in-memory arrays.
1171+
11641172
See Also
11651173
--------
11661174
dask.compute
@@ -1174,12 +1182,18 @@ def persist(self, **kwargs) -> Self:
11741182
This keeps them as dask arrays but encourages them to keep data in
11751183
memory. This is particularly useful when on a distributed machine.
11761184
When on a single machine consider using ``.compute()`` instead.
1185+
Like compute (but unlike load), the original dataset is left unaltered.
11771186
11781187
Parameters
11791188
----------
11801189
**kwargs : dict
11811190
Additional keyword arguments passed on to ``dask.persist``.
11821191
1192+
Returns
1193+
-------
1194+
object : DataArray
1195+
New object with all dask-backed data and coordinates as persisted dask arrays.
1196+
11831197
See Also
11841198
--------
11851199
dask.persist

xarray/core/dataset.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,11 @@ def compute(self, **kwargs) -> Self:
10051005
**kwargs : dict
10061006
Additional keyword arguments passed on to ``dask.compute``.
10071007
1008+
Returns
1009+
-------
1010+
object : Dataset
1011+
New object with lazy data variables and coordinates as in-memory arrays.
1012+
10081013
See Also
10091014
--------
10101015
dask.compute
@@ -1037,12 +1042,18 @@ def persist(self, **kwargs) -> Self:
10371042
operation keeps the data as dask arrays. This is particularly useful
10381043
when using the dask.distributed scheduler and you want to load a large
10391044
amount of data into distributed memory.
1045+
Like compute (but unlike load), the original dataset is left unaltered.
10401046
10411047
Parameters
10421048
----------
10431049
**kwargs : dict
10441050
Additional keyword arguments passed on to ``dask.persist``.
10451051
1052+
Returns
1053+
-------
1054+
object : Dataset
1055+
New object with all dask-backed coordinates and data variables as persisted dask arrays.
1056+
10461057
See Also
10471058
--------
10481059
dask.persist

0 commit comments

Comments
 (0)