Skip to content

Commit b75e41e

Browse files
committed
pr feedback
1 parent 57fd71b commit b75e41e

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

numcodecs/tests/test_zarr3.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
from __future__ import annotations
2-
from typing import Iterator
2+
from collections.abc import Iterator
33

44

55
import numpy as np
66
import pytest
7-
import sys
87

98
from numcodecs.registry import get_codec
109

11-
try:
12-
from zarr.codecs.registry import get_codec_class
13-
from zarr.array import Array
14-
from zarr.common import JSON
15-
from zarr.codecs import BytesCodec
16-
from zarr.abc.store import Store
17-
from zarr.store import MemoryStore, StorePath
1810

19-
except ImportError:
20-
pass
11+
zarr = pytest.importorskip("docutils")
2112

13+
get_codec_class = zarr.codecs.registry.get_codec_class
14+
Array = zarr.array.Array
15+
JSON = zarr.common.JSON
16+
BytesCodec = zarr.codecs.BytesCodec
17+
Store = zarr.abc.store.Store
18+
MemoryStore = zarr.store.MemoryStore
19+
StorePath = zarr.store.StorePath
2220

23-
pytestmark = pytest.mark.skipif(
24-
sys.version_info < (3, 10), reason="zarr-python 3 requires Python 3.10 or higher"
25-
)
21+
22+
EXPECTED_WARNING_STR = "Numcodecs codecs are not in the Zarr version 3.*"
2623

2724

2825
@pytest.fixture
@@ -36,7 +33,7 @@ def store() -> Iterator[Store]:
3633
def test_generic_codec(store: Store, codec_id: str):
3734
data = np.arange(0, 256, dtype="uint16").reshape((16, 16))
3835

39-
with pytest.warns(UserWarning, match="Numcodecs.*"):
36+
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
4037
a = Array.create(
4138
store / "generic",
4239
shape=data.shape,
@@ -50,7 +47,7 @@ def test_generic_codec(store: Store, codec_id: str):
5047
)
5148

5249
a[:, :] = data.copy()
53-
assert np.array_equal(data, a[:, :])
50+
np.testing.assert_array_equal(data, a[:, :])
5451

5552

5653
@pytest.mark.parametrize(
@@ -74,7 +71,7 @@ def test_generic_filter(store: Store, codec_config: dict[str, JSON]):
7471
codec_id = codec_config["id"]
7572
del codec_config["id"]
7673

77-
with pytest.warns(UserWarning, match="Numcodecs.*"):
74+
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
7875
a = Array.create(
7976
store / "generic",
8077
shape=data.shape,
@@ -89,13 +86,13 @@ def test_generic_filter(store: Store, codec_config: dict[str, JSON]):
8986

9087
a[:, :] = data.copy()
9188
a = Array.open(store / "generic")
92-
assert np.array_equal(data, a[:, :])
89+
np.testing.assert_array_equal(data, a[:, :])
9390

9491

9592
def test_generic_filter_bitround(store: Store):
9693
data = np.linspace(0, 1, 256, dtype="float32").reshape((16, 16))
9794

98-
with pytest.warns(UserWarning, match="Numcodecs.*"):
95+
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
9996
a = Array.create(
10097
store / "generic_bitround",
10198
shape=data.shape,
@@ -116,7 +113,7 @@ def test_generic_filter_bitround(store: Store):
116113
def test_generic_filter_quantize(store: Store):
117114
data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16))
118115

119-
with pytest.warns(UserWarning, match="Numcodecs.*"):
116+
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
120117
a = Array.create(
121118
store / "generic_quantize",
122119
shape=data.shape,
@@ -138,7 +135,7 @@ def test_generic_filter_packbits(store: Store):
138135
data = np.zeros((16, 16), dtype="bool")
139136
data[0:4, :] = True
140137

141-
with pytest.warns(UserWarning, match="Numcodecs.*"):
138+
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
142139
a = Array.create(
143140
store / "generic_packbits",
144141
shape=data.shape,
@@ -153,14 +150,14 @@ def test_generic_filter_packbits(store: Store):
153150

154151
a[:, :] = data.copy()
155152
a = Array.open(store / "generic_packbits")
156-
assert np.array_equal(data, a[:, :])
153+
np.testing.assert_array_equal(data, a[:, :])
157154

158155

159156
@pytest.mark.parametrize("codec_id", ["crc32", "adler32", "fletcher32", "jenkins_lookup3"])
160157
def test_generic_checksum(store: Store, codec_id: str):
161158
data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16))
162159

163-
with pytest.warns(UserWarning, match="Numcodecs.*"):
160+
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
164161
a = Array.create(
165162
store / "generic_checksum",
166163
shape=data.shape,
@@ -175,7 +172,7 @@ def test_generic_checksum(store: Store, codec_id: str):
175172

176173
a[:, :] = data.copy()
177174
a = Array.open(store / "generic_checksum")
178-
assert np.array_equal(data, a[:, :])
175+
np.testing.assert_array_equal(data, a[:, :])
179176

180177

181178
@pytest.mark.parametrize("codec_id", ["pcodec", "zfpy"])
@@ -190,7 +187,7 @@ def test_generic_bytes_codec(store: Store, codec_id: str):
190187

191188
data = np.arange(0, 256, dtype="float32").reshape((16, 16))
192189

193-
with pytest.warns(UserWarning, match="Numcodecs.*"):
190+
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
194191
a = Array.create(
195192
store / "generic",
196193
shape=data.shape,
@@ -203,4 +200,4 @@ def test_generic_bytes_codec(store: Store, codec_id: str):
203200
)
204201

205202
a[:, :] = data.copy()
206-
assert np.array_equal(data, a[:, :])
203+
np.testing.assert_array_equal(data, a[:, :])

numcodecs/zarr3.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
import numpy as np
1010
import numcodecs
1111

12+
try:
13+
import zarr
14+
15+
assert zarr.__version__ >= "3.0.0"
16+
except ImportError:
17+
raise ImportError("zarr 3.0.0 or later is required to use the numcodecs zarr integration.")
18+
1219
from zarr.abc.codec import ArrayArrayCodec, BytesBytesCodec, ArrayBytesCodec
1320
from zarr.buffer import NDBuffer, Buffer, BufferPrototype, as_numpy_array_wrapper
1421
from zarr.array_spec import ArraySpec

0 commit comments

Comments
 (0)