Skip to content

Commit 3bd7b8a

Browse files
committed
make all load-related docstrings consistent
1 parent 37be891 commit 3bd7b8a

File tree

3 files changed

+138
-21
lines changed

3 files changed

+138
-21
lines changed

xarray/core/dataarray.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,10 +1135,11 @@ def _dask_finalize(cls, results, name, func, *args, **kwargs) -> Self:
11351135
return cls(variable, coords, name=name, indexes=indexes, fastpath=True)
11361136

11371137
def load(self, **kwargs) -> Self:
1138-
"""Manually trigger loading of this array's data from disk or a
1139-
remote source into memory and return this array.
1138+
"""Trigger loading data into memory and return this dataarray.
11401139
1141-
Unlike compute, the original dataset is modified and returned.
1140+
Data will be computed and/or loaded from disk or a remote source.
1141+
1142+
Unlike ``.compute``, the original dataarray is modified and returned.
11421143
11431144
Normally, it should not be necessary to call this method in user code,
11441145
because all xarray functions should either work on deferred data or
@@ -1150,9 +1151,18 @@ def load(self, **kwargs) -> Self:
11501151
**kwargs : dict
11511152
Additional keyword arguments passed on to ``dask.compute``.
11521153
1154+
Returns
1155+
-------
1156+
object : DataArray
1157+
Same object but with lazy data and coordinates as in-memory arrays.
1158+
11531159
See Also
11541160
--------
11551161
dask.compute
1162+
DataArray.load_async
1163+
DataArray.compute
1164+
Dataset.load
1165+
Variable.load
11561166
"""
11571167
ds = self._to_temp_dataset().load(**kwargs)
11581168
new = self._from_temp_dataset(ds)
@@ -1161,6 +1171,33 @@ def load(self, **kwargs) -> Self:
11611171
return self
11621172

11631173
async def load_async(self, **kwargs) -> Self:
1174+
"""Trigger and await asynchronous loading of data into memory and return this dataarray.
1175+
1176+
Data will be computed and/or loaded from disk or a remote source.
1177+
1178+
Unlike ``.compute``, the original dataarray is modified and returned.
1179+
1180+
Only works when opening data lazily from IO storage backends which support lazy asynchronous loading.
1181+
Otherwise will raise a NotImplementedError.
1182+
1183+
Parameters
1184+
----------
1185+
**kwargs : dict
1186+
Additional keyword arguments passed on to ``dask.compute``.
1187+
1188+
Returns
1189+
-------
1190+
object : Dataarray
1191+
Same object but with lazy data and coordinates as in-memory arrays.
1192+
1193+
See Also
1194+
--------
1195+
dask.compute
1196+
DataArray.compute
1197+
DataArray.load
1198+
Dataset.load_async
1199+
Variable.load_async
1200+
"""
11641201
temp_ds = self._to_temp_dataset()
11651202
ds = await temp_ds.load_async(**kwargs)
11661203
new = self._from_temp_dataset(ds)
@@ -1169,10 +1206,11 @@ async def load_async(self, **kwargs) -> Self:
11691206
return self
11701207

11711208
def compute(self, **kwargs) -> Self:
1172-
"""Manually trigger loading of this array's data from disk or a
1173-
remote source into memory and return a new array.
1209+
"""Trigger loading data into memory and return a new dataarray.
1210+
1211+
Data will be computed and/or loaded from disk or a remote source.
11741212
1175-
Unlike load, the original is left unaltered.
1213+
Unlike ``.load``, the original dataarray is left unaltered.
11761214
11771215
Normally, it should not be necessary to call this method in user code,
11781216
because all xarray functions should either work on deferred data or
@@ -1192,6 +1230,10 @@ def compute(self, **kwargs) -> Self:
11921230
See Also
11931231
--------
11941232
dask.compute
1233+
DataArray.load
1234+
DataArray.load_async
1235+
Dataset.compute
1236+
Variable.compute
11951237
"""
11961238
new = self.copy(deep=False)
11971239
return new.load(**kwargs)

xarray/core/dataset.py

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,11 @@ def dtypes(self) -> Frozen[Hashable, np.dtype]:
521521
)
522522

523523
def load(self, **kwargs) -> Self:
524-
"""Manually trigger loading and/or computation of this dataset's data
525-
from disk or a remote source into memory and return this dataset.
526-
Unlike compute, the original dataset is modified and returned.
524+
"""Trigger loading data into memory and return this dataset.
525+
526+
Data will be computed and/or loaded from disk or a remote source.
527+
528+
Unlike ``.compute``, the original dataset is modified and returned.
527529
528530
Normally, it should not be necessary to call this method in user code,
529531
because all xarray functions should either work on deferred data or
@@ -535,9 +537,18 @@ def load(self, **kwargs) -> Self:
535537
**kwargs : dict
536538
Additional keyword arguments passed on to ``dask.compute``.
537539
540+
Returns
541+
-------
542+
object : Dataset
543+
Same object but with lazy data variables and coordinates as in-memory arrays.
544+
538545
See Also
539546
--------
540547
dask.compute
548+
Dataset.compute
549+
Dataset.load_async
550+
DataArray.load
551+
Variable.load
541552
"""
542553
# access .data to coerce everything to numpy or dask arrays
543554
chunked_data = {
@@ -560,6 +571,33 @@ def load(self, **kwargs) -> Self:
560571
return self
561572

562573
async def load_async(self, **kwargs) -> Self:
574+
"""Trigger and await asynchronous loading of data into memory and return this dataset.
575+
576+
Data will be computed and/or loaded from disk or a remote source.
577+
578+
Unlike ``.compute``, the original dataset is modified and returned.
579+
580+
Only works when opening data lazily from IO storage backends which support lazy asynchronous loading.
581+
Otherwise will raise a NotImplementedError.
582+
583+
Parameters
584+
----------
585+
**kwargs : dict
586+
Additional keyword arguments passed on to ``dask.compute``.
587+
588+
Returns
589+
-------
590+
object : Dataset
591+
Same object but with lazy data variables and coordinates as in-memory arrays.
592+
593+
See Also
594+
--------
595+
dask.compute
596+
Dataset.compute
597+
Dataset.load
598+
DataArray.load_async
599+
Variable.load_async
600+
"""
563601
# TODO refactor this to pull out the common chunked_data codepath
564602

565603
# this blocks on chunked arrays but not on lazily indexed arrays
@@ -722,9 +760,11 @@ def _dask_postpersist(
722760
)
723761

724762
def compute(self, **kwargs) -> Self:
725-
"""Manually trigger loading and/or computation of this dataset's data
726-
from disk or a remote source into memory and return a new dataset.
727-
Unlike load, the original dataset is left unaltered.
763+
"""Trigger loading data into memory and return a new dataset.
764+
765+
Data will be computed and/or loaded from disk or a remote source.
766+
767+
Unlike ``.load``, the original dataset is left unaltered.
728768
729769
Normally, it should not be necessary to call this method in user code,
730770
because all xarray functions should either work on deferred data or
@@ -744,6 +784,10 @@ def compute(self, **kwargs) -> Self:
744784
See Also
745785
--------
746786
dask.compute
787+
Dataset.load
788+
Dataset.load_async
789+
DataArray.compute
790+
Variable.compute
747791
"""
748792
new = self.copy(deep=False)
749793
return new.load(**kwargs)

xarray/core/variable.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -977,8 +977,11 @@ def _replace(
977977
return type(self)(dims, data, attrs, encoding, fastpath=True)
978978

979979
def load(self, **kwargs) -> Self:
980-
"""Manually trigger loading of this variable's data from disk or a
981-
remote source into memory and return this variable.
980+
"""Trigger loading data into memory and return this variable.
981+
982+
Data will be computed and/or loaded from disk or a remote source.
983+
984+
Unlike ``.compute``, the original variable is modified and returned.
982985
983986
Normally, it should not be necessary to call this method in user code,
984987
because all xarray functions should either work on deferred data or
@@ -989,18 +992,28 @@ def load(self, **kwargs) -> Self:
989992
**kwargs : dict
990993
Additional keyword arguments passed on to ``dask.array.compute``.
991994
995+
Returns
996+
-------
997+
object : Variable
998+
Same object but with lazy data as an in-memory array.
999+
9921000
See Also
9931001
--------
1002+
dask.array.compute
9941003
Variable.compute
9951004
Variable.load_async
996-
dask.array.compute
1005+
DataArray.load
1006+
Dataset.load
9971007
"""
9981008
self._data = to_duck_array(self._data, **kwargs)
9991009
return self
10001010

10011011
async def load_async(self, **kwargs) -> Self:
1002-
"""Manually trigger and await asynchronous loading of this variable's data from disk or a
1003-
remote source into memory and return this variable.
1012+
"""Trigger and await asynchronous loading of data into memory and return this variable.
1013+
1014+
Data will be computed and/or loaded from disk or a remote source.
1015+
1016+
Unlike ``.compute``, the original variable is modified and returned.
10041017
10051018
Only works when opening data lazily from IO storage backends which support lazy asynchronous loading.
10061019
Otherwise will raise a NotImplementedError.
@@ -1010,18 +1023,28 @@ async def load_async(self, **kwargs) -> Self:
10101023
**kwargs : dict
10111024
Additional keyword arguments passed on to ``dask.array.compute``.
10121025
1026+
Returns
1027+
-------
1028+
object : Variable
1029+
Same object but with lazy data as an in-memory array.
1030+
10131031
See Also
10141032
--------
1015-
Variable.load
10161033
dask.array.compute
1034+
Variable.load
1035+
Variable.compute
1036+
DataArray.load_async
1037+
Dataset.load_async
10171038
"""
10181039
self._data = await async_to_duck_array(self._data, **kwargs)
10191040
return self
10201041

10211042
def compute(self, **kwargs) -> Self:
1022-
"""Manually trigger loading of this variable's data from disk or a
1023-
remote source into memory and return a new variable. The original is
1024-
left unaltered.
1043+
"""Trigger loading data into memory and return a new variable.
1044+
1045+
Data will be computed and/or loaded from disk or a remote source.
1046+
1047+
The original variable is left unaltered.
10251048
10261049
Normally, it should not be necessary to call this method in user code,
10271050
because all xarray functions should either work on deferred data or
@@ -1032,10 +1055,18 @@ def compute(self, **kwargs) -> Self:
10321055
**kwargs : dict
10331056
Additional keyword arguments passed on to ``dask.array.compute``.
10341057
1058+
Returns
1059+
-------
1060+
object : Variable
1061+
New object with the data as an in-memory array.
1062+
10351063
See Also
10361064
--------
10371065
dask.array.compute
10381066
Variable.load
1067+
Variable.load_async
1068+
DataArray.compute
1069+
Dataset.compute
10391070
"""
10401071
new = self.copy(deep=False)
10411072
return new.load(**kwargs)

0 commit comments

Comments
 (0)