Top level method for putting data on this store, this method: - encodes variables/attributes - sets dimensions - sets variables Parameters ---------- variables : dict-like Dictionary of key/value (variable name / xr.Variable
(
self,
variables,
attributes,
check_encoding_set=frozenset(),
writer=None,
unlimited_dims=None,
)
| 986 | return encode_zarr_attr_value(a) |
| 987 | |
| 988 | def store( |
| 989 | self, |
| 990 | variables, |
| 991 | attributes, |
| 992 | check_encoding_set=frozenset(), |
| 993 | writer=None, |
| 994 | unlimited_dims=None, |
| 995 | ): |
| 996 | """ |
| 997 | Top level method for putting data on this store, this method: |
| 998 | - encodes variables/attributes |
| 999 | - sets dimensions |
| 1000 | - sets variables |
| 1001 | |
| 1002 | Parameters |
| 1003 | ---------- |
| 1004 | variables : dict-like |
| 1005 | Dictionary of key/value (variable name / xr.Variable) pairs |
| 1006 | attributes : dict-like |
| 1007 | Dictionary of key/value (attribute name / attribute) pairs |
| 1008 | check_encoding_set : list-like |
| 1009 | List of variables that should be checked for invalid encoding |
| 1010 | values |
| 1011 | writer : ArrayWriter |
| 1012 | unlimited_dims : list-like |
| 1013 | List of dimension names that should be treated as unlimited |
| 1014 | dimensions. |
| 1015 | dimension on which the zarray will be appended |
| 1016 | only needed in append mode |
| 1017 | """ |
| 1018 | if TYPE_CHECKING: |
| 1019 | import zarr |
| 1020 | else: |
| 1021 | zarr = attempt_import("zarr") |
| 1022 | |
| 1023 | if self._mode == "w": |
| 1024 | # always overwrite, so we don't care about existing names, |
| 1025 | # and consistency of encoding |
| 1026 | new_variable_names = set(variables) |
| 1027 | existing_keys = {} |
| 1028 | existing_variable_names = {} |
| 1029 | else: |
| 1030 | existing_keys = self.array_keys() |
| 1031 | existing_variable_names = { |
| 1032 | vn for vn in variables if _encode_variable_name(vn) in existing_keys |
| 1033 | } |
| 1034 | new_variable_names = set(variables) - existing_variable_names |
| 1035 | |
| 1036 | if self._mode == "r+" and ( |
| 1037 | new_names := [k for k in variables if k not in existing_keys] |
| 1038 | ): |
| 1039 | raise ValueError( |
| 1040 | f"dataset contains non-pre-existing variables {new_names!r}, " |
| 1041 | "which is not allowed in ``xarray.Dataset.to_zarr()`` with " |
| 1042 | "``mode='r+'``. To allow writing new variables, set ``mode='a'``." |
| 1043 | ) |
| 1044 | |
| 1045 | if self._append_dim is not None and self._append_dim not in existing_keys: |
no test coverage detected