Skip to content

Commit

Permalink
Minor to_zarr optimizations (#8489)
Browse files Browse the repository at this point in the history
Co-authored-by: Anderson Banihirwe <[email protected]>
  • Loading branch information
dcherian and andersy005 authored Dec 1, 2023
1 parent d46c5b6 commit b703102
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,9 @@ def store(
"""
import zarr

existing_keys = tuple(self.zarr_group.array_keys())
existing_variable_names = {
vn for vn in variables if _encode_variable_name(vn) in self.zarr_group
vn for vn in variables if _encode_variable_name(vn) in existing_keys
}
new_variables = set(variables) - existing_variable_names
variables_without_encoding = {vn: variables[vn] for vn in new_variables}
Expand Down Expand Up @@ -665,6 +666,8 @@ def set_variables(self, variables, check_encoding_set, writer, unlimited_dims=No

import zarr

existing_keys = tuple(self.zarr_group.array_keys())

for vn, v in variables.items():
name = _encode_variable_name(vn)
check = vn in check_encoding_set
Expand All @@ -677,7 +680,7 @@ def set_variables(self, variables, check_encoding_set, writer, unlimited_dims=No
if v.encoding == {"_FillValue": None} and fill_value is None:
v.encoding = {}

if name in self.zarr_group:
if name in existing_keys:
# existing variable
# TODO: if mode="a", consider overriding the existing variable
# metadata. This would need some case work properly with region
Expand Down

0 comments on commit b703102

Please sign in to comment.