diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index 4723b0ad48..975b1235e6 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -43,7 +43,6 @@ from xarray.core.datatree import DataTree - @functools.lru_cache def _zarr_v3() -> bool: try: @@ -89,8 +88,10 @@ def __init__(self, zarr_array): self.shape = self._array.shape # preserve vlen string object dtype (GH 7328) - if not _zarr_v3() and self._array.filters is not None and any( - [filt.codec_id == "vlen-utf8" for filt in self._array.filters] + if ( + not _zarr_v3() + and self._array.filters is not None + and any([filt.codec_id == "vlen-utf8" for filt in self._array.filters]) ): dtype = coding.strings.create_vlen_dtype(str) else: @@ -633,17 +634,23 @@ def open_store_variable(self, name, zarr_array=None): } if _zarr_v3() and zarr_array.metadata.zarr_format == 3: - encoding["codec_pipeline"] = [x.to_dict() for x in zarr_array.metadata.codecs] + encoding["codec_pipeline"] = [ + x.to_dict() for x in zarr_array.metadata.codecs + ] elif _zarr_v3(): - encoding.update({ - "compressor": zarr_array.metadata.compressor, - "filters": zarr_array.metadata.filters, - }) + encoding.update( + { + "compressor": zarr_array.metadata.compressor, + "filters": zarr_array.metadata.filters, + } + ) else: - encoding.update({ - "compressor": zarr_array.compressor, - "filters": zarr_array.filters, - }) + encoding.update( + { + "compressor": zarr_array.compressor, + "filters": zarr_array.filters, + } + ) # _FillValue needs to be in attributes, not encoding, so it will get # picked up by decode_cf diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 91ee357d6a..35a573b451 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -2255,7 +2255,9 @@ def test_roundtrip_consolidated(self, consolidated) -> None: def test_read_non_consolidated_warning(self) -> None: expected = create_test_data() with self.create_zarr_target() as store: - self.save(expected, store_target=store, consolidated=False, **self.version_kwargs) + self.save( + expected, store_target=store, consolidated=False, **self.version_kwargs + ) with pytest.warns( RuntimeWarning, match="Failed to open Zarr store with consolidated", @@ -3044,7 +3046,12 @@ def test_encoding_chunksizes(self) -> None: # see also test_encoding_chunksizes_unlimited nx, ny, nt = 4, 4, 5 original = xr.Dataset( - {}, coords={"x": np.arange(nx) + 1 , "y": np.arange(ny) + 1, "t": np.arange(nt) + 1} + {}, + coords={ + "x": np.arange(nx) + 1, + "y": np.arange(ny) + 1, + "t": np.arange(nt) + 1, + }, ) original["v"] = xr.Variable(("x", "y", "t"), np.zeros((nx, ny, nt))) original = original.chunk({"t": 1, "x": 2, "y": 2}) @@ -3304,6 +3311,7 @@ class TestZarrDictStore(ZarrBase): def create_zarr_target(self): if have_zarr_v3: import zarr.store + yield zarr.store.MemoryStore({}, mode="w") else: yield {}