Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrappers for zarr v3 #524

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4f7c12c
import zarr-python#1839
normanrz May 6, 2024
f6d2652
pep8
normanrz May 6, 2024
9593c43
remove try/catch
normanrz May 8, 2024
2dc9281
pep8
normanrz May 8, 2024
1822576
update to latest zarr-python interfaces
normanrz May 17, 2024
636624b
Merge remote-tracking branch 'origin/main' into zarr3-codecs
normanrz Jun 12, 2024
8ba9da7
flake
normanrz Jun 12, 2024
3459871
add zarr-python to ci
normanrz Jun 12, 2024
8e10124
fix import
normanrz Jun 12, 2024
14807a5
tests
normanrz Jun 12, 2024
9932a1d
fixes
normanrz Jun 12, 2024
2a12c40
skip zarr3 tests on older python versions
normanrz Jun 13, 2024
92f247d
merge
normanrz Jun 24, 2024
cd49cf7
ruff
normanrz Jun 24, 2024
5083d66
add zfpy and pcodec
normanrz Jun 25, 2024
64e081a
Merge remote-tracking branch 'origin/main' into zarr3-codecs
normanrz Jun 25, 2024
7a40530
remove zarr from dependencies
normanrz Jun 25, 2024
2654737
change prefix
normanrz Jun 25, 2024
8c37d5d
fixes for ci
normanrz Jun 25, 2024
37700a5
fix for tests
normanrz Jun 25, 2024
c9c8f5e
Merge branch 'main' into zarr3-codecs
normanrz Jul 9, 2024
57fd71b
Merge branch 'main' into zarr3-codecs
normanrz Sep 16, 2024
b75e41e
pr feedback
normanrz Sep 24, 2024
a4cf7ad
Sync with zarr 3 beta (#597)
mpiannucci Oct 16, 2024
860956f
Update numcodecs/tests/test_zarr3.py
normanrz Oct 16, 2024
a62d258
moves zarr3 to private module, adds test for zarr-python2 installs
normanrz Oct 18, 2024
6d8bad2
Merge remote-tracking branch 'origin/main' into zarr3-codecs
normanrz Oct 18, 2024
f28775d
add typing_extensions as dep
normanrz Oct 18, 2024
6a8115c
tests
normanrz Oct 18, 2024
82fa7a8
importorskip minversion
normanrz Oct 18, 2024
20aa698
ci install
normanrz Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
python-version: ["3.10", "3.11", "3.12", "3.13.0"]
# macos-12 is an intel runner, macos-14 is a arm64 runner
platform: [ubuntu-latest, windows-latest, macos-12, macos-14]
zarr-version: ["zarr>=2,<3", "zarr==3.0.0b0"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I lost track of this - I think you convinced me earlier in the comments of this PR that we could just install zarr==3 here and not bother testing with zarr v2?


steps:
- name: Checkout source
Expand Down Expand Up @@ -71,6 +72,13 @@ jobs:
python -m pip install -v pcodec


- name: Install zarr-python
if : matrix.python-version != '3.10'
shell: "bash -l {0}"
run: |
conda activate env
python -m pip install '${{ matrix.zarr-version }}'

# This is used to test with zfpy, which does not yet support numpy 2.0
- name: Install older numpy and zfpy
if: matrix.python-version == '3.10'
Expand Down
284 changes: 284 additions & 0 deletions numcodecs/_zarr3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
from __future__ import annotations

import asyncio
import math
from dataclasses import dataclass, replace
from functools import cached_property
from warnings import warn

import numpy as np
from typing_extensions import Self

import numcodecs

try:
import zarr

if zarr.__version__ < "3.0.0":
raise ImportError("zarr 3.0.0 or later is required to use the numcodecs zarr integration.")
except ImportError:
raise ImportError("zarr 3.0.0 or later is required to use the numcodecs zarr integration.")

from zarr.abc.codec import ArrayArrayCodec, ArrayBytesCodec, BytesBytesCodec
from zarr.core.array_spec import ArraySpec
from zarr.core.buffer import Buffer, BufferPrototype, NDBuffer
from zarr.core.buffer.cpu import as_numpy_array_wrapper
from zarr.core.common import (

Check warning on line 26 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L22-L26

Added lines #L22 - L26 were not covered by tests
JSON,
parse_named_configuration,
product,
)
from zarr.core.metadata import ArrayMetadata

Check warning on line 31 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L31

Added line #L31 was not covered by tests

CODEC_PREFIX = "numcodecs."

Check warning on line 33 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L33

Added line #L33 was not covered by tests


def parse_codec_configuration(data: dict[str, JSON], expected_name_prefix: str) -> dict[str, JSON]:
parsed_name, parsed_configuration = parse_named_configuration(data)
if not parsed_name.startswith(expected_name_prefix):
raise ValueError(

Check warning on line 39 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L36-L39

Added lines #L36 - L39 were not covered by tests
f"Expected name to start with '{expected_name_prefix}'. Got {parsed_name} instead."
)
id = parsed_name[slice(len(expected_name_prefix), None)]
return {"id": id, **parsed_configuration}

Check warning on line 43 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L42-L43

Added lines #L42 - L43 were not covered by tests


@dataclass(frozen=True)
class NumcodecsCodec:
codec_config: dict[str, JSON]

Check warning on line 48 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L46-L48

Added lines #L46 - L48 were not covered by tests

def __init__(self, *, codec_id: str | None = None, codec_config: dict[str, JSON]) -> None:
if "id" not in codec_config:
if not codec_id:
raise ValueError(

Check warning on line 53 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L50-L53

Added lines #L50 - L53 were not covered by tests
"The codec id needs to be supplied either through the id attribute "
"of the codec_config or through the codec_id argument."
)
codec_config = {"id": codec_id, **codec_config}
elif codec_id and codec_config["id"] != codec_id:
raise ValueError(f"Codec id does not match {codec_id}. Got: {codec_config['id']}.")

Check warning on line 59 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L57-L59

Added lines #L57 - L59 were not covered by tests

object.__setattr__(self, "codec_config", codec_config)
warn(

Check warning on line 62 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L61-L62

Added lines #L61 - L62 were not covered by tests
"Numcodecs codecs are not in the Zarr version 3 specification and "
"may not be supported by other zarr implementations.",
category=UserWarning,
)

@cached_property
def _codec(self) -> numcodecs.abc.Codec:
return numcodecs.get_codec(self.codec_config)

Check warning on line 70 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L68-L70

Added lines #L68 - L70 were not covered by tests

@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
codec_config = parse_codec_configuration(data, CODEC_PREFIX)
assert isinstance(codec_config["id"], str) # for mypy
return cls(codec_config=codec_config)

Check warning on line 76 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L72-L76

Added lines #L72 - L76 were not covered by tests

def to_dict(self) -> JSON:
codec_config = self.codec_config.copy()
codec_id = codec_config.pop("id")
return {

Check warning on line 81 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L78-L81

Added lines #L78 - L81 were not covered by tests
"name": f"{CODEC_PREFIX}{codec_id}",
"configuration": codec_config,
}

def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
return input_byte_length

Check warning on line 87 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L86-L87

Added lines #L86 - L87 were not covered by tests


class NumcodecsBytesBytesCodec(NumcodecsCodec, BytesBytesCodec):
def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None:
super().__init__(codec_id=codec_id, codec_config=codec_config)

Check warning on line 92 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L90-L92

Added lines #L90 - L92 were not covered by tests

async def _decode_single(self, chunk_bytes: Buffer, chunk_spec: ArraySpec) -> Buffer:
return await asyncio.to_thread(

Check warning on line 95 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L94-L95

Added lines #L94 - L95 were not covered by tests
as_numpy_array_wrapper,
self._codec.decode,
chunk_bytes,
chunk_spec.prototype,
)

def _encode(self, chunk_bytes: Buffer, prototype: BufferPrototype) -> Buffer:
encoded = self._codec.encode(chunk_bytes.as_array_like())
if isinstance(encoded, np.ndarray): # Required for checksum codecs
return prototype.buffer.from_bytes(encoded.tobytes())
return prototype.buffer.from_bytes(encoded)

Check warning on line 106 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L102-L106

Added lines #L102 - L106 were not covered by tests

async def _encode_single(self, chunk_bytes: Buffer, chunk_spec: ArraySpec) -> Buffer:
return await asyncio.to_thread(self._encode, chunk_bytes, chunk_spec.prototype)

Check warning on line 109 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L108-L109

Added lines #L108 - L109 were not covered by tests


class NumcodecsArrayArrayCodec(NumcodecsCodec, ArrayArrayCodec):
def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None:
super().__init__(codec_id=codec_id, codec_config=codec_config)

Check warning on line 114 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L112-L114

Added lines #L112 - L114 were not covered by tests

async def _decode_single(self, chunk_array: NDBuffer, chunk_spec: ArraySpec) -> NDBuffer:
chunk_ndarray = chunk_array.as_ndarray_like()
out = await asyncio.to_thread(self._codec.decode, chunk_ndarray)
return chunk_spec.prototype.nd_buffer.from_ndarray_like(out.reshape(chunk_spec.shape))

Check warning on line 119 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L116-L119

Added lines #L116 - L119 were not covered by tests

async def _encode_single(self, chunk_array: NDBuffer, chunk_spec: ArraySpec) -> NDBuffer:
chunk_ndarray = chunk_array.as_ndarray_like()
out = await asyncio.to_thread(self._codec.encode, chunk_ndarray)
return chunk_spec.prototype.nd_buffer.from_ndarray_like(out)

Check warning on line 124 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L121-L124

Added lines #L121 - L124 were not covered by tests


class NumcodecsArrayBytesCodec(NumcodecsCodec, ArrayBytesCodec):
def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None:
super().__init__(codec_id=codec_id, codec_config=codec_config)

Check warning on line 129 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L127-L129

Added lines #L127 - L129 were not covered by tests

async def _decode_single(self, chunk_buffer: Buffer, chunk_spec: ArraySpec) -> NDBuffer:
chunk_bytes = chunk_buffer.to_bytes()
out = await asyncio.to_thread(self._codec.decode, chunk_bytes)
return chunk_spec.prototype.nd_buffer.from_ndarray_like(out.reshape(chunk_spec.shape))

Check warning on line 134 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L131-L134

Added lines #L131 - L134 were not covered by tests

async def _encode_single(self, chunk_ndbuffer: NDBuffer, chunk_spec: ArraySpec) -> Buffer:
chunk_ndarray = chunk_ndbuffer.as_ndarray_like()
out = await asyncio.to_thread(self._codec.encode, chunk_ndarray)
return chunk_spec.prototype.buffer.from_bytes(out)

Check warning on line 139 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L136-L139

Added lines #L136 - L139 were not covered by tests


def make_bytes_bytes_codec(codec_id: str, cls_name: str) -> type[NumcodecsBytesBytesCodec]:

Check warning on line 142 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L142

Added line #L142 was not covered by tests
# rename for class scope
_codec_id = codec_id

Check warning on line 144 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L144

Added line #L144 was not covered by tests

class _Codec(NumcodecsBytesBytesCodec):
def __init__(self, codec_config: dict[str, JSON] = {}) -> None:
super().__init__(codec_id=_codec_id, codec_config=codec_config)

Check warning on line 148 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L146-L148

Added lines #L146 - L148 were not covered by tests

_Codec.__name__ = cls_name
return _Codec

Check warning on line 151 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L150-L151

Added lines #L150 - L151 were not covered by tests


def make_array_array_codec(codec_id: str, cls_name: str) -> type[NumcodecsArrayArrayCodec]:

Check warning on line 154 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L154

Added line #L154 was not covered by tests
# rename for class scope
_codec_id = codec_id

Check warning on line 156 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L156

Added line #L156 was not covered by tests

class _Codec(NumcodecsArrayArrayCodec):
def __init__(self, codec_config: dict[str, JSON] = {}) -> None:
super().__init__(codec_id=_codec_id, codec_config=codec_config)

Check warning on line 160 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L158-L160

Added lines #L158 - L160 were not covered by tests

_Codec.__name__ = cls_name
return _Codec

Check warning on line 163 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L162-L163

Added lines #L162 - L163 were not covered by tests


def make_array_bytes_codec(codec_id: str, cls_name: str) -> type[NumcodecsArrayBytesCodec]:

Check warning on line 166 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L166

Added line #L166 was not covered by tests
# rename for class scope
_codec_id = codec_id

Check warning on line 168 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L168

Added line #L168 was not covered by tests

class _Codec(NumcodecsArrayBytesCodec):
def __init__(self, codec_config: dict[str, JSON] = {}) -> None:
super().__init__(codec_id=_codec_id, codec_config=codec_config)

Check warning on line 172 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L170-L172

Added lines #L170 - L172 were not covered by tests

_Codec.__name__ = cls_name
return _Codec

Check warning on line 175 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L174-L175

Added lines #L174 - L175 were not covered by tests


def make_checksum_codec(codec_id: str, cls_name: str) -> type[NumcodecsBytesBytesCodec]:

Check warning on line 178 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L178

Added line #L178 was not covered by tests
# rename for class scope
_codec_id = codec_id

Check warning on line 180 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L180

Added line #L180 was not covered by tests

class _ChecksumCodec(NumcodecsBytesBytesCodec):
def __init__(self, codec_config: dict[str, JSON] = {}) -> None:
super().__init__(codec_id=_codec_id, codec_config=codec_config)

Check warning on line 184 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L182-L184

Added lines #L182 - L184 were not covered by tests

def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
return input_byte_length + 4

Check warning on line 187 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L186-L187

Added lines #L186 - L187 were not covered by tests

_ChecksumCodec.__name__ = cls_name
return _ChecksumCodec

Check warning on line 190 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L189-L190

Added lines #L189 - L190 were not covered by tests


class ShuffleCodec(NumcodecsBytesBytesCodec):
def __init__(self, codec_config: dict[str, JSON] = {}) -> None:
super().__init__(codec_id="shuffle", codec_config=codec_config)

Check warning on line 195 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L193-L195

Added lines #L193 - L195 were not covered by tests

def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
if array_spec.dtype.itemsize != self.codec_config.get("elementsize"):
return self.__class__({**self.codec_config, "elementsize": array_spec.dtype.itemsize})
return self

Check warning on line 200 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L197-L200

Added lines #L197 - L200 were not covered by tests


class FixedScaleOffsetCodec(NumcodecsArrayArrayCodec):
def __init__(self, codec_config: dict[str, JSON] = {}) -> None:
super().__init__(codec_id="fixedscaleoffset", codec_config=codec_config)

Check warning on line 205 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L203-L205

Added lines #L203 - L205 were not covered by tests

def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
if astype := self.codec_config.get("astype"):
return replace(chunk_spec, dtype=np.dtype(astype))
return chunk_spec

Check warning on line 210 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L207-L210

Added lines #L207 - L210 were not covered by tests

def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
if str(array_spec.dtype) != self.codec_config.get("dtype"):
return self.__class__({**self.codec_config, "dtype": str(array_spec.dtype)})
return self

Check warning on line 215 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L212-L215

Added lines #L212 - L215 were not covered by tests


class QuantizeCodec(NumcodecsArrayArrayCodec):
def __init__(self, codec_config: dict[str, JSON] = {}) -> None:
super().__init__(codec_id="quantize", codec_config=codec_config)

Check warning on line 220 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L218-L220

Added lines #L218 - L220 were not covered by tests

def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
if str(array_spec.dtype) != self.codec_config.get("dtype"):
return self.__class__({**self.codec_config, "dtype": str(array_spec.dtype)})
return self

Check warning on line 225 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L222-L225

Added lines #L222 - L225 were not covered by tests


class AsTypeCodec(NumcodecsArrayArrayCodec):
def __init__(self, codec_config: dict[str, JSON] = {}) -> None:
super().__init__(codec_id="astype", codec_config=codec_config)

Check warning on line 230 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L228-L230

Added lines #L228 - L230 were not covered by tests

def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
return replace(chunk_spec, dtype=np.dtype(self.codec_config["encode_dtype"]))

Check warning on line 233 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L232-L233

Added lines #L232 - L233 were not covered by tests

def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
decode_dtype = self.codec_config.get("decode_dtype")
if str(array_spec.dtype) != decode_dtype:
return self.__class__({**self.codec_config, "decode_dtype": str(array_spec.dtype)})
return self

Check warning on line 239 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L235-L239

Added lines #L235 - L239 were not covered by tests


class PackbitsCodec(NumcodecsArrayArrayCodec):
def __init__(self, codec_config: dict[str, JSON] = {}) -> None:
super().__init__(codec_id="packbits", codec_config=codec_config)

Check warning on line 244 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L242-L244

Added lines #L242 - L244 were not covered by tests

def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
return replace(

Check warning on line 247 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L246-L247

Added lines #L246 - L247 were not covered by tests
chunk_spec,
shape=(1 + math.ceil(product(chunk_spec.shape) / 8),),
dtype=np.dtype("uint8"),
)

def validate(self, array_metadata: ArrayMetadata) -> None:
if array_metadata.dtype != np.dtype("bool"):
raise ValueError(f"Packbits filter requires bool dtype. Got {array_metadata.dtype}.")

Check warning on line 255 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L253-L255

Added lines #L253 - L255 were not covered by tests


# bytes-to-bytes codecs
BloscCodec = make_bytes_bytes_codec("blosc", "BloscCodec")
Lz4Codec = make_bytes_bytes_codec("lz4", "Lz4Codec")
ZstdCodec = make_bytes_bytes_codec("zstd", "ZstdCodec")
ZlibCodec = make_bytes_bytes_codec("zlib", "ZlibCodec")
GzipCodec = make_bytes_bytes_codec("gzip", "GzipCodec")
Bz2Codec = make_bytes_bytes_codec("bz2", "Bz2Codec")
LzmaCodec = make_bytes_bytes_codec("lzma", "LzmaCodec")

Check warning on line 265 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L259-L265

Added lines #L259 - L265 were not covered by tests
# ShuffleCodec

# array-to-array codecs ("filters")
DeltaCodec = make_array_array_codec("delta", "DeltaCodec")
BitroundCodec = make_array_array_codec("bitround", "BitroundCodec")

Check warning on line 270 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L269-L270

Added lines #L269 - L270 were not covered by tests
# FixedScaleOffsetCodec
# QuantizeCodec
# PackbitsCodec
# AsTypeCodec

# bytes-to-bytes checksum codecs
Crc32Codec = make_checksum_codec("crc32", "Crc32Codec")
Adler32Codec = make_checksum_codec("adler32", "Adler32Codec")
Fletcher32Codec = make_checksum_codec("fletcher32", "Fletcher32Codec")
JenkinsLookup3Codec = make_checksum_codec("jenkins_lookup3", "JenkinsLookup3Codec")

Check warning on line 280 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L277-L280

Added lines #L277 - L280 were not covered by tests

# array-to-bytes codecs
PCodecCodec = make_array_bytes_codec("pcodec", "PCodecCodec")
ZFPYCodec = make_array_bytes_codec("zfpy", "ZFPYCodec")

Check warning on line 284 in numcodecs/_zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/_zarr3.py#L283-L284

Added lines #L283 - L284 were not covered by tests
Loading
Loading