Skip to content

Commit

Permalink
use the new Zarr Context
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Apr 17, 2023
1 parent 8437e65 commit 9284c96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 10 additions & 1 deletion python/kvikio/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numpy
import zarr.storage
import zarr.version

import kvikio

Expand All @@ -26,6 +27,11 @@ class GDSStore(zarr.storage.DirectoryStore):
This is because only zarr.Array use getitems() to retrieve data.
"""

def __init__(self, *args, **kwargs) -> None:
if zarr.version.version_tuple < (2, 15):
raise RuntimeError("GDSStore requires Zarr v2.15+")
super().__init__(*args, **kwargs)

def __eq__(self, other):
return isinstance(other, GDSStore) and self.path == other.path

Expand All @@ -35,7 +41,10 @@ def _tofile(self, a, fn):
assert written == a.nbytes

def getitems(
self, keys: Sequence[str], contexts: Mapping[str, Mapping] = {}
self,
keys: Sequence[str],
*,
contexts: Mapping[str, Mapping] = {},
) -> Mapping[str, Any]:

default_meta_array = numpy.empty(())
Expand Down
13 changes: 6 additions & 7 deletions python/tests/test_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
zarr = pytest.importorskip("zarr")
GDSStore = pytest.importorskip("kvikio.zarr").GDSStore

# To support CuPy arrays, we need the `meta_array` argument introduced in
# Zarr v2.13, see <https://github.com/zarr-developers/zarr-python/pull/934>
if not hasattr(zarr.Array, "meta_array"):
pytest.skip("requires Zarr v2.13+", allow_module_level=True)

# To support CuPy arrays, we need the `Context` argument introduced in
# Zarr v2.15, see <https://github.com/zarr-developers/zarr-python/pull/1131>
if zarr.version.version_tuple < (2, 15):
pytest.skip("requires Zarr v2.15+", allow_module_level=True)


@pytest.fixture
Expand All @@ -21,11 +22,9 @@ def store(tmp_path):
return GDSStore(tmp_path / "test-file.zarr")


@pytest.mark.parametrize("array_type", ["numpy", "cupy"])
def test_direct_store_access(store, array_type):
def test_direct_store_access(store, xp):
"""Test accessing the GDS Store directly"""

xp = pytest.importorskip(array_type)
a = xp.arange(5, dtype="u1")
store["a"] = a
b = store["a"]
Expand Down

0 comments on commit 9284c96

Please sign in to comment.