Skip to content

Commit e31bb2f

Browse files
committed
wip docs
1 parent bc2e704 commit e31bb2f

File tree

5 files changed

+246
-64
lines changed

5 files changed

+246
-64
lines changed

docs/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ API reference
1010
checksum32
1111
abc
1212
registry
13+
zarr3

docs/zarr3.rst

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
Zarr 3 codecs
2+
=============
3+
.. automodule:: numcodecs.zarr3
4+
5+
6+
Bytes-to-bytes codecs
7+
---------------------
8+
.. autoclass:: BloscCodec()
9+
10+
.. autoattribute:: codec_name
11+
12+
.. autoclass:: Lz4Codec()
13+
14+
.. autoattribute:: codec_name
15+
16+
.. autoclass:: ZstdCodec()
17+
18+
.. autoattribute:: codec_name
19+
20+
.. autoclass:: ZlibCodec()
21+
22+
.. autoattribute:: codec_name
23+
24+
.. autoclass:: GzipCodec()
25+
26+
.. autoattribute:: codec_name
27+
28+
.. autoclass:: Bz2Codec()
29+
30+
.. autoattribute:: codec_name
31+
32+
.. autoclass:: LzmaCodec()
33+
34+
.. autoattribute:: codec_name
35+
36+
.. autoclass:: ShuffleCodec()
37+
38+
.. autoattribute:: codec_name
39+
40+
41+
Array-to-array codecs
42+
---------------------
43+
.. autoclass:: DeltaCodec()
44+
45+
.. autoattribute:: codec_name
46+
47+
.. autoclass:: BitroundCodec()
48+
49+
.. autoattribute:: codec_name
50+
51+
.. autoclass:: FixedScaleOffsetCodec()
52+
53+
.. autoattribute:: codec_name
54+
55+
.. autoclass:: QuantizeCodec()
56+
57+
.. autoattribute:: codec_name
58+
59+
.. autoclass:: PackbitsCodec()
60+
61+
.. autoattribute:: codec_name
62+
63+
.. autoclass:: AsTypeCodec()
64+
65+
.. autoattribute:: codec_name
66+
67+
68+
Bytes-to-bytes checksum codecs
69+
------------------------------
70+
.. autoclass:: Crc32Codec()
71+
72+
.. autoattribute:: codec_name
73+
74+
.. autoclass:: Crc32cCodec()
75+
76+
.. autoattribute:: codec_name
77+
78+
.. autoclass:: Adler32Codec()
79+
80+
.. autoattribute:: codec_name
81+
82+
.. autoclass:: Fletcher32Codec()
83+
84+
.. autoattribute:: codec_name
85+
86+
.. autoclass:: JenkinsLookup3Codec()
87+
88+
.. autoattribute:: codec_name
89+
90+
91+
Array-to-bytes codecs
92+
---------------------
93+
.. autoclass:: PCodecCodec()
94+
95+
.. autoattribute:: codec_name
96+
97+
.. autoclass:: ZFPYCodec()
98+
99+
.. autoattribute:: codec_name

numcodecs/tests/test_zarr3.py

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
import pytest
55

66
from numcodecs.registry import get_codec
7+
from numcodecs.zarr3 import (
8+
BloscCodec,
9+
BZ2Codec,
10+
GZipCodec,
11+
LZ4Codec,
12+
LZMACodec,
13+
NumcodecsCodec,
14+
ShuffleCodec,
15+
ZlibCodec,
16+
ZstdCodec,
17+
)
718

819
zarr = pytest.importorskip("zarr")
920

@@ -29,9 +40,42 @@ def store() -> Store:
2940

3041

3142
@pytest.mark.parametrize(
32-
"codec_id", ["blosc", "lz4", "zstd", "zlib", "gzip", "bz2", "lzma", "shuffle"]
43+
"codec_name", ["blosc", "lz4", "zstd", "zlib", "gzip", "bz2", "lzma", "shuffle"]
44+
)
45+
def test_generic_codec(store: Store, codec_name: str):
46+
data = np.arange(0, 256, dtype="uint16").reshape((16, 16))
47+
48+
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
49+
a = Array.create(
50+
store / "generic",
51+
shape=data.shape,
52+
chunk_shape=(16, 16),
53+
dtype=data.dtype,
54+
fill_value=0,
55+
codecs=[
56+
BytesCodec(),
57+
get_codec_class(f"numcodecs.{codec_name}")({"id": codec_name}),
58+
],
59+
)
60+
61+
a[:, :] = data.copy()
62+
np.testing.assert_array_equal(data, a[:, :])
63+
64+
65+
@pytest.mark.parametrize(
66+
"codec_class",
67+
[
68+
BloscCodec,
69+
LZ4Codec,
70+
ZstdCodec,
71+
ZlibCodec,
72+
GZipCodec,
73+
BZ2Codec,
74+
LZMACodec,
75+
ShuffleCodec,
76+
],
3377
)
34-
def test_generic_codec(store: Store, codec_id: str):
78+
def test_generic_codec_class(store: Store, codec_class: type[NumcodecsCodec]):
3579
data = np.arange(0, 256, dtype="uint16").reshape((16, 16))
3680

3781
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
@@ -43,7 +87,7 @@ def test_generic_codec(store: Store, codec_id: str):
4387
fill_value=0,
4488
codecs=[
4589
BytesCodec(),
46-
get_codec_class(f"numcodecs.{codec_id}")({"id": codec_id}),
90+
codec_class(),
4791
],
4892
)
4993

@@ -69,7 +113,7 @@ def test_generic_codec(store: Store, codec_id: str):
69113
def test_generic_filter(store: Store, codec_config: dict[str, JSON]):
70114
data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16))
71115

72-
codec_id = codec_config["id"]
116+
codec_name = codec_config["id"]
73117
del codec_config["id"]
74118

75119
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
@@ -80,7 +124,7 @@ def test_generic_filter(store: Store, codec_config: dict[str, JSON]):
80124
dtype=data.dtype,
81125
fill_value=0,
82126
codecs=[
83-
get_codec_class(f"numcodecs.{codec_id}")(codec_config),
127+
get_codec_class(f"numcodecs.{codec_name}")(codec_config),
84128
BytesCodec(),
85129
],
86130
)
@@ -167,8 +211,8 @@ def test_generic_filter_packbits(store: Store):
167211
)
168212

169213

170-
@pytest.mark.parametrize("codec_id", ["crc32", "adler32", "fletcher32", "jenkins_lookup3"])
171-
def test_generic_checksum(store: Store, codec_id: str):
214+
@pytest.mark.parametrize("codec_name", ["crc32", "adler32", "fletcher32", "jenkins_lookup3"])
215+
def test_generic_checksum(store: Store, codec_name: str):
172216
data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16))
173217

174218
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
@@ -180,7 +224,7 @@ def test_generic_checksum(store: Store, codec_id: str):
180224
fill_value=0,
181225
codecs=[
182226
BytesCodec(),
183-
get_codec_class(f"numcodecs.{codec_id}")(),
227+
get_codec_class(f"numcodecs.{codec_name}")(),
184228
],
185229
)
186230

@@ -189,17 +233,17 @@ def test_generic_checksum(store: Store, codec_id: str):
189233
np.testing.assert_array_equal(data, a[:, :])
190234

191235

192-
@pytest.mark.parametrize("codec_id", ["pcodec", "zfpy"])
193-
def test_generic_bytes_codec(store: Store, codec_id: str):
236+
@pytest.mark.parametrize("codec_name", ["pcodec", "zfpy"])
237+
def test_generic_bytes_codec(store: Store, codec_name: str):
194238
try:
195-
get_codec({"id": codec_id})
239+
get_codec({"id": codec_name})
196240
except ValueError as e:
197241
if "codec not available" in str(e):
198-
pytest.xfail(f"{codec_id} is not available: {e}")
242+
pytest.xfail(f"{codec_name} is not available: {e}")
199243
else:
200244
raise # pragma: no cover
201245
except ImportError as e:
202-
pytest.xfail(f"{codec_id} is not available: {e}")
246+
pytest.xfail(f"{codec_name} is not available: {e}")
203247

204248
data = np.arange(0, 256, dtype="float32").reshape((16, 16))
205249

@@ -211,7 +255,7 @@ def test_generic_bytes_codec(store: Store, codec_id: str):
211255
dtype=data.dtype,
212256
fill_value=0,
213257
codecs=[
214-
get_codec_class(f"numcodecs.{codec_id}")({"id": codec_id}),
258+
get_codec_class(f"numcodecs.{codec_name}")({"id": codec_name}),
215259
],
216260
)
217261

0 commit comments

Comments
 (0)