From 9700c57eab5769620c820ee61b3809b47b0ca31f Mon Sep 17 00:00:00 2001 From: "Mads R. B. Kristensen" Date: Thu, 5 Oct 2023 13:26:42 +0200 Subject: [PATCH] check non-CUDA compatible compressor --- python/kvikio/zarr.py | 6 ++++++ python/tests/test_zarr.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/python/kvikio/zarr.py b/python/kvikio/zarr.py index 481e6e96d6..b6f8154b72 100644 --- a/python/kvikio/zarr.py +++ b/python/kvikio/zarr.py @@ -381,6 +381,12 @@ def open_cupy_array( meta_array=meta_array, **kwargs, ) + elif not isinstance(ret.compressor, CudaCodec): + raise ValueError( + "The Zarr file was written using a non-CUDA compatible " + f"compressor, {ret.compressor}, please use something " + "like kvikio.zarr.CompatCompressor" + ) return ret if isinstance(compressor, CompatCompressor): diff --git a/python/tests/test_zarr.py b/python/tests/test_zarr.py index f909559eea..cc0ee0ebdd 100644 --- a/python/tests/test_zarr.py +++ b/python/tests/test_zarr.py @@ -245,3 +245,11 @@ def test_open_cupy_array(tmp_path): assert isinstance(z[:], numpy.ndarray) assert z.compressor == kvikio_zarr.CompatCompressor.lz4().cpu numpy.testing.assert_array_equal(a.get(), z[:]) + + +@pytest.mark.parametrize("mode", ["r", "r+"]) +def test_open_cupy_array_incompatible_compressor(tmp_path, mode): + zarr.create((10,), store=tmp_path, compressor=numcodecs.Blosc()) + + with pytest.raises(ValueError, match="non-CUDA compatible compressor"): + kvikio_zarr.open_cupy_array(tmp_path, mode=mode)