From eb37aedf980b74929b6f98a0bbe9e757672cacc1 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Fri, 22 Mar 2024 12:32:14 -0600 Subject: [PATCH] Optimize writes to existing Zarr stores. We need to read existing variables to make sure we append or write to a region with the right encoding. Currently we request all arrays in a Zarr group. Instead only request those arrays for which we require encoding information. --- xarray/backends/zarr.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index e9465dc0ba0..baf38d2ad16 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -623,7 +623,12 @@ def store( # avoid needing to load index variables into memory. # TODO: consider making loading indexes lazy again? existing_vars, _, _ = conventions.decode_cf_variables( - self.get_variables(), self.get_attrs() + { + k: v + for k, v in self.get_variables().items() + if k in existing_variable_names + }, + self.get_attrs(), ) # Modified variables must use the same encoding as the store. vars_with_encoding = {}