Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ Release notes

.. _unreleased:

Unreleased
----------

Fixes
~~~~~
* Fixes issue with ``Delta`` Zarr 3 codec not working with ``astype``.
By :user:`Norman Rzepka <normanrz>`, :issue:`664`


Improvements
~~~~~~~~~~~~


0.14.1
------

Expand Down
2 changes: 2 additions & 0 deletions docs/zarr3.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _Zarr 3 codecs:

Zarr 3 codecs
=============
.. automodule:: numcodecs.zarr3
Expand Down
21 changes: 21 additions & 0 deletions numcodecs/tests/test_zarr3.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,24 @@ def test_generic_bytes_codec(store: StorePath, codec_class: type[numcodecs.zarr3

a[:, :] = data.copy()
np.testing.assert_array_equal(data, a[:, :])


def test_delta_astype(store: StorePath):
data = np.linspace(0, 10, 256, dtype="i8").reshape((16, 16))

with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
a = Array.create(
store / "generic",
shape=data.shape,
chunk_shape=(16, 16),
dtype=data.dtype,
fill_value=0,
codecs=[
numcodecs.zarr3.Delta(dtype="i8", astype="i2"), # type: ignore[arg-type]
BytesCodec(),
],
)

a[:, :] = data.copy()
a = Array.open(store / "generic")
np.testing.assert_array_equal(data, a[:, :])
14 changes: 13 additions & 1 deletion numcodecs/zarr3.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,19 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Shuffle:


# array-to-array codecs ("filters")
Delta = _add_docstring(_make_array_array_codec("delta", "Delta"), "numcodecs.delta.Delta")
@_add_docstring_wrapper("numcodecs.delta.Delta")
class Delta(_NumcodecsArrayArrayCodec):
codec_name = f"{CODEC_PREFIX}delta"

def __init__(self, **codec_config: dict[str, JSON]) -> None:
super().__init__(**codec_config)

def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
if astype := self.codec_config.get("astype"):
return replace(chunk_spec, dtype=np.dtype(astype)) # type: ignore[arg-type]
return chunk_spec


BitRound = _add_docstring(
_make_array_array_codec("bitround", "BitRound"), "numcodecs.bitround.BitRound"
)
Expand Down
Loading