diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index c49a41de108..6c93de53dcb 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -4344,14 +4344,22 @@ def to_zarr( Store or path to directory in local or remote file system only for Zarr array chunks. Requires zarr-python v2.4.0 or later. mode : {"w", "w-", "a", "a-", r+", None}, optional - Persistence mode: "w" means create (overwrite if exists); - "w-" means create (fail if exists); - "a" means override all existing variables including dimension coordinates (create if does not exist); - "a-" means only append those variables that have ``append_dim``. - "r+" means modify existing array *values* only (raise an error if - any metadata or shapes would change). + Persistence mode: + + - "w" means create (remove old if exists and write new); + - "w-" means create (fail if exists); + - "a" means override all existing variables including dimension coordinates (create if does not exist); + - "a-" means only append those variables that have ``append_dim``. + - "r+" means modify existing array *values* only (raise an error if + any metadata or shapes would change). + The default mode is "a" if ``append_dim`` is set. Otherwise, it is "r+" if ``region`` is set and ``w-`` otherwise. + + .. note:: + When modifying an existing Zarr array that is lazily opened, the "w" + behavior can be surprising since the underlying file that is being + lazily read from might get deleted before the data is computed. synchronizer : object, optional Zarr array synchronizer. group : str, optional diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index c1e1b961f22..248f53d687b 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -2233,14 +2233,22 @@ def to_zarr( Store or path to directory in local or remote file system only for Zarr array chunks. Requires zarr-python v2.4.0 or later. mode : {"w", "w-", "a", "a-", r+", None}, optional - Persistence mode: "w" means create (overwrite if exists); - "w-" means create (fail if exists); - "a" means override all existing variables including dimension coordinates (create if does not exist); - "a-" means only append those variables that have ``append_dim``. - "r+" means modify existing array *values* only (raise an error if - any metadata or shapes would change). + Persistence mode: + + - "w" means create (remove old if exists and write new); + - "w-" means create (fail if exists); + - "a" means override all existing variables including dimension coordinates (create if does not exist); + - "a-" means only append those variables that have ``append_dim``. + - "r+" means modify existing array *values* only (raise an error if + any metadata or shapes would change). + The default mode is "a" if ``append_dim`` is set. Otherwise, it is "r+" if ``region`` is set and ``w-`` otherwise. + + .. note:: + When modifying an existing Zarr array that is lazily opened, the "w" + behavior can be surprising since the underlying file that is being + lazily read from might get deleted before the data is computed. synchronizer : object, optional Zarr array synchronizer. group : str, optional diff --git a/xarray/core/datatree.py b/xarray/core/datatree.py index 65feb8da4c9..98934f29b92 100644 --- a/xarray/core/datatree.py +++ b/xarray/core/datatree.py @@ -2157,10 +2157,20 @@ def to_zarr( store : zarr.storage.StoreLike Store or path to directory in file system mode : {{"w", "w-", "a", "r+", None}, default: "w-" - Persistence mode: “w” means create (overwrite if exists); “w-” means create (fail if exists); - “a” means override existing variables (create if does not exist); “r+” means modify existing - array values only (raise an error if any metadata or shapes would change). The default mode - is “w-”. + Persistence mode: + + - "w" means create (remove old if exists and write new); + - "w-" means create (fail if exists); + - "a" means override all existing variables including dimension coordinates (create if does not exist); + - "r+" means modify existing array *values* only (raise an error if + any metadata or shapes would change). + + The default mode is “w-”. + + .. note:: + When modifying an existing Zarr array that is lazily opened, the "w" + behavior can be surprising since the underlying file that is being + lazily read from might get deleted before the data is computed. encoding : dict, optional Nested dictionary with variable names as keys and dictionaries of variable specific encodings as values, e.g.,