3939from xarray .core .dataset import Dataset , _get_chunk , _maybe_chunk
4040from xarray .core .indexes import Index
4141from xarray .core .parallelcompat import guess_chunkmanager
42+ from xarray .core .types import ZarrWriteModes
4243from xarray .core .utils import is_remote_uri
4344
4445if TYPE_CHECKING :
6970 "NETCDF4" , "NETCDF4_CLASSIC" , "NETCDF3_64BIT" , "NETCDF3_CLASSIC"
7071 ]
7172
72-
7373DATAARRAY_NAME = "__xarray_dataarray_name__"
7474DATAARRAY_VARIABLE = "__xarray_dataarray_variable__"
7575
@@ -1577,7 +1577,7 @@ def to_zarr(
15771577 dataset : Dataset ,
15781578 store : MutableMapping | str | os .PathLike [str ] | None = None ,
15791579 chunk_store : MutableMapping | str | os .PathLike | None = None ,
1580- mode : Literal [ "w" , "w-" , "a" , "r+" , None ] = None ,
1580+ mode : ZarrWriteModes | None = None ,
15811581 synchronizer = None ,
15821582 group : str | None = None ,
15831583 encoding : Mapping | None = None ,
@@ -1601,7 +1601,7 @@ def to_zarr(
16011601 dataset : Dataset ,
16021602 store : MutableMapping | str | os .PathLike [str ] | None = None ,
16031603 chunk_store : MutableMapping | str | os .PathLike | None = None ,
1604- mode : Literal [ "w" , "w-" , "a" , "r+" , None ] = None ,
1604+ mode : ZarrWriteModes | None = None ,
16051605 synchronizer = None ,
16061606 group : str | None = None ,
16071607 encoding : Mapping | None = None ,
@@ -1623,7 +1623,7 @@ def to_zarr(
16231623 dataset : Dataset ,
16241624 store : MutableMapping | str | os .PathLike [str ] | None = None ,
16251625 chunk_store : MutableMapping | str | os .PathLike | None = None ,
1626- mode : Literal [ "w" , "w-" , "a" , "r+" , None ] = None ,
1626+ mode : ZarrWriteModes | None = None ,
16271627 synchronizer = None ,
16281628 group : str | None = None ,
16291629 encoding : Mapping | None = None ,
@@ -1680,16 +1680,18 @@ def to_zarr(
16801680 else :
16811681 mode = "w-"
16821682
1683- if mode != "a" and append_dim is not None :
1683+ if mode not in [ "a" , "a-" ] and append_dim is not None :
16841684 raise ValueError ("cannot set append_dim unless mode='a' or mode=None" )
16851685
1686- if mode not in ["a" , "r+" ] and region is not None :
1687- raise ValueError ("cannot set region unless mode='a', mode='r+' or mode=None" )
1686+ if mode not in ["a" , "a-" , "r+" ] and region is not None :
1687+ raise ValueError (
1688+ "cannot set region unless mode='a', mode='a-', mode='r+' or mode=None"
1689+ )
16881690
1689- if mode not in ["w" , "w-" , "a" , "r+" ]:
1691+ if mode not in ["w" , "w-" , "a" , "a-" , " r+" ]:
16901692 raise ValueError (
16911693 "The only supported options for mode are 'w', "
1692- f"'w-', 'a' and 'r+', but mode={ mode !r} "
1694+ f"'w-', 'a', 'a-', and 'r+', but mode={ mode !r} "
16931695 )
16941696
16951697 # validate Dataset keys, DataArray names
@@ -1745,7 +1747,7 @@ def to_zarr(
17451747 write_empty = write_empty_chunks ,
17461748 )
17471749
1748- if mode in ["a" , "r+" ]:
1750+ if mode in ["a" , "a-" , " r+" ]:
17491751 _validate_datatypes_for_zarr_append (zstore , dataset )
17501752 if append_dim is not None :
17511753 existing_dims = zstore .get_dimensions ()
0 commit comments