From 7b13099a4313d449565a0522dbd13016a198fc37 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:19:07 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/backends/zarr.py | 14 +++++++++----- xarray/tests/test_backends.py | 17 ++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index 6af763ea0c9..6a3448bd942 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -38,12 +38,14 @@ from xarray.namedarray.utils import module_available if TYPE_CHECKING: + from zarr import Array as ZarrArray + from zarr import Group as ZarrGroup + from xarray.backends.common import AbstractDataStore from xarray.core.dataset import Dataset from xarray.core.datatree import DataTree from xarray.core.types import ReadBuffer - from zarr import Array as ZarrArray - from zarr import Group as ZarrGroup + def _get_mappers(*, storage_options, store, chunk_store): # expand str and path-like arguments @@ -735,7 +737,6 @@ def __init__( use_zarr_fill_value_as_mask=None, cache_members: bool = True, ): - self.zarr_group = zarr_group self._read_only = self.zarr_group.read_only self._synchronizer = self.zarr_group.synchronizer @@ -753,10 +754,10 @@ def __init__( if self._cache_members: # initialize the cache - # this cache is created here and never updated. + # this cache is created here and never updated. # If the `ZarrStore` instance creates a new zarr array, or if an external process # removes an existing zarr array, then the cache will be invalid. - # create a new ZarrStore instance if you want to + # create a new ZarrStore instance if you want to # capture the current state of the zarr group, or create a ZarrStore with # `cache_members` set to `False` to disable this cache and instead fetch members # on demand. @@ -778,6 +779,7 @@ def _fetch_members(self) -> dict[str, ZarrArray]: Get the arrays and groups defined in the zarr group modelled by this Store """ import zarr + if zarr.__version__ >= "3": return dict(self.zarr_group.members()) else: @@ -785,12 +787,14 @@ def _fetch_members(self) -> dict[str, ZarrArray]: def array_keys(self) -> tuple[str, ...]: from zarr import Array as ZarrArray + return tuple( key for (key, node) in self.members.items() if isinstance(node, ZarrArray) ) def arrays(self) -> tuple[tuple[str, ZarrArray], ...]: from zarr import Array as ZarrArray + return tuple( (key, node) for (key, node) in self.members.items() diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index f7b0f413206..21e59e004ad 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -407,14 +407,14 @@ def test_zero_dimensional_variable(self) -> None: with self.roundtrip(expected) as actual: assert_identical(expected, actual) - def test_write_store(self) -> None: - expected = create_test_data() - with self.create_store() as store: - expected.dump_to_store(store) - # we need to cf decode the store because it has time and - # non-dimension coordinates - with xr.decode_cf(store) as actual: - assert_allclose(expected, actual) + def test_write_store(self) -> None: + expected = create_test_data() + with self.create_store() as store: + expected.dump_to_store(store) + # we need to cf decode the store because it has time and + # non-dimension coordinates + with xr.decode_cf(store) as actual: + assert_allclose(expected, actual) def check_dtypes_roundtripped(self, expected, actual): for k in expected.variables: @@ -3340,7 +3340,6 @@ def create_zarr_target(self): store = KVStore({}, **kwargs) # type: ignore[arg-type,unused-ignore] yield store - def make_patches(self, store): from unittest.mock import MagicMock