Skip to content

Commit

Permalink
revert revert, because I reverted too much
Browse files Browse the repository at this point in the history
  • Loading branch information
d-v-b committed Dec 10, 2024
1 parent ffb9a8e commit a7602f6
Showing 1 changed file with 27 additions and 36 deletions.
63 changes: 27 additions & 36 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -2275,13 +2275,10 @@ def create_zarr_target(self):
raise NotImplementedError

@contextlib.contextmanager
def create_store(self, cache_members: bool = True):
def create_store(self):
with self.create_zarr_target() as store_target:
yield backends.ZarrStore.open_group(
store_target,
mode="w",
cache_members=cache_members,
**self.version_kwargs,
store_target, mode="w", **self.version_kwargs
)

def save(self, dataset, store_target, **kwargs): # type: ignore[override]
Expand Down Expand Up @@ -2575,7 +2572,7 @@ def test_hidden_zarr_keys(self) -> None:
skip_if_zarr_format_3("This test is unnecessary; no hidden Zarr keys")

expected = create_test_data()
with self.create_store(cache_members=False) as store:
with self.create_store() as store:
expected.dump_to_store(store)
zarr_group = store.ds

Expand All @@ -2597,7 +2594,6 @@ def test_hidden_zarr_keys(self) -> None:

# put it back and try removing from a variable
del zarr_group["var2"].attrs[self.DIMENSION_KEY]

with pytest.raises(KeyError):

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10

TestZarrWriteEmpty.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10

TestZarrDictStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10

TestZarrDirectoryStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 min-all-deps

TestZarrDictStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 min-all-deps

TestZarrDirectoryStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 min-all-deps

TestZarrWriteEmpty.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11 all-but-dask

TestZarrDictStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11 all-but-dask

TestZarrDirectoryStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11 all-but-dask

TestZarrWriteEmpty.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.12

TestZarrWriteEmpty.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.12

TestZarrDictStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.12

TestZarrDirectoryStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12

TestZarrWriteEmpty.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12

TestZarrDictStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12

TestZarrDirectoryStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.10

TestZarrWriteEmpty.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.10

TestZarrDictStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.10

TestZarrDirectoryStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-numba

TestZarrWriteEmpty.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>

Check failure on line 2597 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-numba

TestZarrDictStore.test_hidden_zarr_keys[2] Failed: DID NOT RAISE <class 'KeyError'>
with xr.decode_cf(store):
pass
Expand Down Expand Up @@ -3262,43 +3258,40 @@ def test_chunked_cftime_datetime(self) -> None:
assert original[name].chunks == actual_var.chunks
assert original.chunks == actual.chunks

def test_cache_members(self) -> None:
@pytest.mark.parametrize("cache_array_keys", [True, False])
def test_get_array_keys(self, cache_array_keys: bool) -> None:
"""
Ensure that if `ZarrStore` is created with `cache_members` set to `True`,
a `ZarrStore` only inspects the underlying zarr group once,
and that the results of that inspection are cached.
Ensure that if `ZarrStore` is created with `cache_array_keys` set to `True`,
a `ZarrStore.get_array_keys` only invokes the `array_keys` function on the
`ZarrStore.zarr_group` instance once, and that the results of that call are cached.
Otherwise, `ZarrStore.members` should inspect the underlying zarr group each time it is
invoked
Otherwise, `ZarrStore.get_array_keys` instance should invoke the `array_keys`
each time it is called.
"""
with self.create_zarr_target() as store_target:
zstore_mut = backends.ZarrStore.open_group(
store_target, mode="w", cache_members=False
zstore = backends.ZarrStore.open_group(

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10

TestZarrWriteEmpty.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10

TestZarrWriteEmpty.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10

TestZarrDictStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10

TestZarrDictStore.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10

TestZarrDirectoryStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 min-all-deps

TestZarrDictStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 min-all-deps

TestZarrDictStore.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 min-all-deps

TestZarrDirectoryStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 min-all-deps

TestZarrDirectoryStore.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 min-all-deps

TestZarrWriteEmpty.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10 min-all-deps

TestZarrWriteEmpty.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11 all-but-dask

TestZarrWriteEmpty.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11 all-but-dask

TestZarrWriteEmpty.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11 all-but-dask

TestZarrDictStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11 all-but-dask

TestZarrDictStore.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11 all-but-dask

TestZarrDirectoryStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11 all-but-dask

TestZarrDirectoryStore.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.12

TestZarrWriteEmpty.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.12

TestZarrWriteEmpty.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.12

TestZarrDictStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.12

TestZarrDictStore.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.12

TestZarrDirectoryStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12

TestZarrWriteEmpty.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12

TestZarrWriteEmpty.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12

TestZarrDictStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12

TestZarrDictStore.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12

TestZarrDirectoryStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.10

TestZarrWriteEmpty.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.10

TestZarrWriteEmpty.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.10

TestZarrDictStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.10

TestZarrDictStore.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.10

TestZarrDirectoryStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-numba

TestZarrDirectoryStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-numba

TestZarrDirectoryStore.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-numba

TestZarrWriteEmpty.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-numba

TestZarrWriteEmpty.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-numba

TestZarrDictStore.test_get_array_keys[2-True] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'

Check failure on line 3272 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 all-but-numba

TestZarrDictStore.test_get_array_keys[2-False] TypeError: ZarrStore.open_group() got an unexpected keyword argument 'cache_array_keys'
store_target, mode="w", cache_array_keys=cache_array_keys
)

# ensure that the keys are sorted
array_keys = sorted(("foo", "bar"))

# create some arrays
for ak in array_keys:
zstore_mut.zarr_group.create(name=ak, shape=(1,), dtype="uint8")

zstore_stat = backends.ZarrStore.open_group(
store_target, mode="r", cache_members=True
)
zstore.zarr_group.create(name=ak, shape=(1,), dtype="uint8")

observed_keys_0 = sorted(zstore_stat.array_keys())
observed_keys_0 = sorted(zstore.get_array_keys())
assert observed_keys_0 == array_keys

# create a new array
new_key = "baz"
zstore_mut.zarr_group.create(name=new_key, shape=(1,), dtype="uint8")

observed_keys_1 = sorted(zstore_stat.array_keys())
assert observed_keys_1 == array_keys
zstore.zarr_group.create(name=new_key, shape=(1,), dtype="uint8")
observed_keys_1 = sorted(zstore.get_array_keys())

observed_keys_2 = sorted(zstore_mut.array_keys())
assert observed_keys_2 == sorted(array_keys + [new_key])
if cache_array_keys:
assert observed_keys_1 == array_keys
else:
assert observed_keys_1 == sorted(array_keys + [new_key])


@requires_zarr
Expand Down Expand Up @@ -3378,11 +3371,11 @@ def test_append(self) -> None:
}
else:
expected = {
"iter": 2,
"iter": 3,
"contains": 18,
"setitem": 10,
"getitem": 13,
"listdir": 1,
"listdir": 2,
"list_prefix": 2,
}

Expand Down Expand Up @@ -3480,11 +3473,11 @@ def test_region_write(self) -> None:
}
else:
expected = {
"iter": 1,
"iter": 2,
"contains": 4,
"setitem": 1,
"getitem": 5,
"listdir": 1,
"getitem": 4,
"listdir": 2,
"list_prefix": 0,
}

Expand Down Expand Up @@ -3563,11 +3556,9 @@ def create_zarr_target(self):
yield tmp

@contextlib.contextmanager
def create_store(self, cache_members: bool = True):
def create_store(self):
with self.create_zarr_target() as store_target:
group = backends.ZarrStore.open_group(
store_target, mode="a", cache_members=cache_members
)
group = backends.ZarrStore.open_group(store_target, mode="a")
yield group


Expand Down

0 comments on commit a7602f6

Please sign in to comment.