Skip to content

Commit c37e7cf

Browse files
committed
docs
1 parent b2e18ca commit c37e7cf

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

numcodecs/tests/test_zarr3.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,20 @@ def store() -> Store:
2828
return StorePath(MemoryStore(mode="w"))
2929

3030

31-
@pytest.mark.parametrize(
32-
("codec_name", "codec_class"),
33-
[
34-
("numcodecs.blosc", numcodecs.zarr3.Blosc),
35-
("numcodecs.lz4", numcodecs.zarr3.LZ4),
36-
("numcodecs.zstd", numcodecs.zarr3.Zstd),
37-
("numcodecs.zlib", numcodecs.zarr3.Zlib),
38-
("numcodecs.gzip", numcodecs.zarr3.GZip),
39-
("numcodecs.bz2", numcodecs.zarr3.BZ2),
40-
("numcodecs.lzma", numcodecs.zarr3.LZMA),
41-
("numcodecs.shuffle", numcodecs.zarr3.Shuffle),
42-
("numcodecs.delta", numcodecs.zarr3.Delta),
43-
("numcodecs.bitround", numcodecs.zarr3.BitRound),
44-
("numcodecs.fixedscaleoffset", numcodecs.zarr3.FixedScaleOffset),
45-
("numcodecs.quantize", numcodecs.zarr3.Quantize),
46-
("numcodecs.packbits", numcodecs.zarr3.PackBits),
47-
("numcodecs.astype", numcodecs.zarr3.AsType),
48-
("numcodecs.crc32", numcodecs.zarr3.CRC32),
49-
("numcodecs.crc32c", numcodecs.zarr3.CRC32C),
50-
("numcodecs.adler32", numcodecs.zarr3.Adler32),
51-
("numcodecs.fletcher32", numcodecs.zarr3.Fletcher32),
52-
("numcodecs.jenkins_lookup3", numcodecs.zarr3.JenkinsLookup3),
53-
("numcodecs.pcodec", numcodecs.zarr3.PCodec),
54-
("numcodecs.zfpy", numcodecs.zarr3.ZFPY),
55-
],
56-
)
57-
def test_entry_points(codec_name: str, codec_class: type[numcodecs.zarr3._NumcodecsCodec]):
58-
assert codec_class.codec_name == codec_name
31+
ALL_CODECS = [getattr(numcodecs.zarr3, cls_name) for cls_name in numcodecs.zarr3.__all__]
32+
33+
34+
@pytest.mark.parametrize("codec_class", ALL_CODECS)
35+
def test_entry_points(codec_class: type[numcodecs.zarr3._NumcodecsCodec]):
36+
codec_name = codec_class.codec_name
5937
assert get_codec_class(codec_name) == codec_class
6038

6139

40+
@pytest.mark.parametrize("codec_class", ALL_CODECS)
41+
def test_docstring(codec_class: type[numcodecs.zarr3._NumcodecsCodec]):
42+
assert "See :class:`numcodecs." in codec_class.__doc__
43+
44+
6245
@pytest.mark.parametrize(
6346
"codec_class",
6447
[

numcodecs/zarr3.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626

2727
import asyncio
2828
import math
29+
from collections.abc import Callable
2930
from dataclasses import dataclass, replace
30-
from functools import cached_property
31+
from functools import cached_property, partial
3132
from typing import Any, Self, TypeVar
3233
from warnings import warn
3334

@@ -180,6 +181,10 @@ def _add_docstring(cls: type[T], ref_class_name: str) -> type[T]:
180181
return cls
181182

182183

184+
def _add_docstring_wrapper(ref_class_name: str) -> Callable[[type[T]], type[T]]:
185+
return partial(_add_docstring, ref_class_name=ref_class_name)
186+
187+
183188
def _make_bytes_bytes_codec(codec_name: str, cls_name: str) -> type[_NumcodecsBytesBytesCodec]:
184189
# rename for class scope
185190
_codec_name = CODEC_PREFIX + codec_name
@@ -249,6 +254,7 @@ def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) ->
249254
LZMA = _add_docstring(_make_bytes_bytes_codec("lzma", "LZMA"), "numcodecs.lzma.LZMA")
250255

251256

257+
@_add_docstring_wrapper("numcodecs.shuffle.Shuffle")
252258
class Shuffle(_NumcodecsBytesBytesCodec):
253259
codec_name = f"{CODEC_PREFIX}shuffle"
254260

@@ -261,15 +267,14 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
261267
return self # pragma: no cover
262268

263269

264-
Shuffle = _add_docstring(Shuffle, "numcodecs.shuffle.Shuffle")
265-
266270
# array-to-array codecs ("filters")
267271
Delta = _add_docstring(_make_array_array_codec("delta", "Delta"), "numcodecs.delta.Delta")
268272
BitRound = _add_docstring(
269273
_make_array_array_codec("bitround", "BitRound"), "numcodecs.bitround.BitRound"
270274
)
271275

272276

277+
@_add_docstring_wrapper("numcodecs.fixedscaleoffset.FixedScaleOffset")
273278
class FixedScaleOffset(_NumcodecsArrayArrayCodec):
274279
codec_name = f"{CODEC_PREFIX}fixedscaleoffset"
275280

@@ -287,9 +292,7 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
287292
return self
288293

289294

290-
FixedScaleOffset = _add_docstring(FixedScaleOffset, "numcodecs.fixedscaleoffset.FixedScaleOffset")
291-
292-
295+
@_add_docstring_wrapper("numcodecs.quantize.Quantize")
293296
class Quantize(_NumcodecsArrayArrayCodec):
294297
codec_name = f"{CODEC_PREFIX}quantize"
295298

@@ -302,9 +305,7 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
302305
return self
303306

304307

305-
_add_docstring(Quantize, "numcodecs.quantize.Quantize")
306-
307-
308+
@_add_docstring_wrapper("numcodecs.packbits.PackBits")
308309
class PackBits(_NumcodecsArrayArrayCodec):
309310
codec_name = f"{CODEC_PREFIX}packbits"
310311

@@ -323,9 +324,7 @@ def validate(self, *, dtype: np.dtype[Any], **_kwargs) -> None:
323324
raise ValueError(f"Packbits filter requires bool dtype. Got {dtype}.")
324325

325326

326-
PackBits = _add_docstring(PackBits, "numcodecs.packbits.PackBits")
327-
328-
327+
@_add_docstring_wrapper("numcodecs.astype.AsType")
329328
class AsType(_NumcodecsArrayArrayCodec):
330329
codec_name = f"{CODEC_PREFIX}astype"
331330

@@ -342,8 +341,6 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
342341
return self
343342

344343

345-
AsType = _add_docstring(AsType, "numcodecs.astype.AsType")
346-
347344
# bytes-to-bytes checksum codecs
348345
CRC32 = _add_docstring(_make_checksum_codec("crc32", "CRC32"), "numcodecs.checksum32.CRC32")
349346
CRC32C = _add_docstring(_make_checksum_codec("crc32c", "CRC32C"), "numcodecs.checksum32.CRC32C")
@@ -358,3 +355,27 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
358355
# array-to-bytes codecs
359356
PCodec = _add_docstring(_make_array_bytes_codec("pcodec", "PCodec"), "numcodecs.pcodec.PCodec")
360357
ZFPY = _add_docstring(_make_array_bytes_codec("zfpy", "ZFPY"), "numcodecs.zfpy.ZFPY")
358+
359+
__all__ = [
360+
"Blosc",
361+
"LZ4",
362+
"Zstd",
363+
"Zlib",
364+
"GZip",
365+
"BZ2",
366+
"LZMA",
367+
"Shuffle",
368+
"Delta",
369+
"BitRound",
370+
"FixedScaleOffset",
371+
"Quantize",
372+
"PackBits",
373+
"AsType",
374+
"CRC32",
375+
"CRC32C",
376+
"Adler32",
377+
"Fletcher32",
378+
"JenkinsLookup3",
379+
"PCodec",
380+
"ZFPY",
381+
]

0 commit comments

Comments
 (0)