Skip to content

Commit 13dc9ab

Browse files
authored
DOCS: Clarify what mode means in docstring for to_zarr (#11229)
* Clarify what mode means in docstring for `to_zarr` * Make docstring a real list
1 parent 78707f5 commit 13dc9ab

3 files changed

Lines changed: 42 additions & 16 deletions

File tree

xarray/core/dataarray.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4344,14 +4344,22 @@ def to_zarr(
43444344
Store or path to directory in local or remote file system only for Zarr
43454345
array chunks. Requires zarr-python v2.4.0 or later.
43464346
mode : {"w", "w-", "a", "a-", r+", None}, optional
4347-
Persistence mode: "w" means create (overwrite if exists);
4348-
"w-" means create (fail if exists);
4349-
"a" means override all existing variables including dimension coordinates (create if does not exist);
4350-
"a-" means only append those variables that have ``append_dim``.
4351-
"r+" means modify existing array *values* only (raise an error if
4352-
any metadata or shapes would change).
4347+
Persistence mode:
4348+
4349+
- "w" means create (remove old if exists and write new);
4350+
- "w-" means create (fail if exists);
4351+
- "a" means override all existing variables including dimension coordinates (create if does not exist);
4352+
- "a-" means only append those variables that have ``append_dim``.
4353+
- "r+" means modify existing array *values* only (raise an error if
4354+
any metadata or shapes would change).
4355+
43534356
The default mode is "a" if ``append_dim`` is set. Otherwise, it is
43544357
"r+" if ``region`` is set and ``w-`` otherwise.
4358+
4359+
.. note::
4360+
When modifying an existing Zarr array that is lazily opened, the "w"
4361+
behavior can be surprising since the underlying file that is being
4362+
lazily read from might get deleted before the data is computed.
43554363
synchronizer : object, optional
43564364
Zarr array synchronizer.
43574365
group : str, optional

xarray/core/dataset.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,14 +2233,22 @@ def to_zarr(
22332233
Store or path to directory in local or remote file system only for Zarr
22342234
array chunks. Requires zarr-python v2.4.0 or later.
22352235
mode : {"w", "w-", "a", "a-", r+", None}, optional
2236-
Persistence mode: "w" means create (overwrite if exists);
2237-
"w-" means create (fail if exists);
2238-
"a" means override all existing variables including dimension coordinates (create if does not exist);
2239-
"a-" means only append those variables that have ``append_dim``.
2240-
"r+" means modify existing array *values* only (raise an error if
2241-
any metadata or shapes would change).
2236+
Persistence mode:
2237+
2238+
- "w" means create (remove old if exists and write new);
2239+
- "w-" means create (fail if exists);
2240+
- "a" means override all existing variables including dimension coordinates (create if does not exist);
2241+
- "a-" means only append those variables that have ``append_dim``.
2242+
- "r+" means modify existing array *values* only (raise an error if
2243+
any metadata or shapes would change).
2244+
22422245
The default mode is "a" if ``append_dim`` is set. Otherwise, it is
22432246
"r+" if ``region`` is set and ``w-`` otherwise.
2247+
2248+
.. note::
2249+
When modifying an existing Zarr array that is lazily opened, the "w"
2250+
behavior can be surprising since the underlying file that is being
2251+
lazily read from might get deleted before the data is computed.
22442252
synchronizer : object, optional
22452253
Zarr array synchronizer.
22462254
group : str, optional

xarray/core/datatree.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,10 +2157,20 @@ def to_zarr(
21572157
store : zarr.storage.StoreLike
21582158
Store or path to directory in file system
21592159
mode : {{"w", "w-", "a", "r+", None}, default: "w-"
2160-
Persistence mode: “w” means create (overwrite if exists); “w-” means create (fail if exists);
2161-
“a” means override existing variables (create if does not exist); “r+” means modify existing
2162-
array values only (raise an error if any metadata or shapes would change). The default mode
2163-
is “w-”.
2160+
Persistence mode:
2161+
2162+
- "w" means create (remove old if exists and write new);
2163+
- "w-" means create (fail if exists);
2164+
- "a" means override all existing variables including dimension coordinates (create if does not exist);
2165+
- "r+" means modify existing array *values* only (raise an error if
2166+
any metadata or shapes would change).
2167+
2168+
The default mode is “w-”.
2169+
2170+
.. note::
2171+
When modifying an existing Zarr array that is lazily opened, the "w"
2172+
behavior can be surprising since the underlying file that is being
2173+
lazily read from might get deleted before the data is computed.
21642174
encoding : dict, optional
21652175
Nested dictionary with variable names as keys and dictionaries of
21662176
variable specific encodings as values, e.g.,

0 commit comments

Comments
 (0)