Skip to content

Commit 6bc140f

Browse files
committed
fixes #663
1 parent f43449b commit 6bc140f

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

docs/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Fixes
2525
``crc32c`` is not installed. This has been changed to match
2626
the behaviour of other optional dependencies/codecs.
2727
By :user:`John Kirkham <jakirkham>`, :issue:`637`
28+
* Fixes issue with ``Delta`` Zarr 3 codec not working with ``astype``.
29+
By :user:`Norman Rzepka <normanrz>`, :issue:`664`
2830

2931
Improvements
3032
~~~~~~~~~~~~

docs/zarr3.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _Zarr 3 codecs:
2+
13
Zarr 3 codecs
24
=============
35
.. automodule:: numcodecs.zarr3

numcodecs/tests/test_zarr3.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,24 @@ def test_generic_bytes_codec(store: StorePath, codec_class: type[numcodecs.zarr3
244244

245245
a[:, :] = data.copy()
246246
np.testing.assert_array_equal(data, a[:, :])
247+
248+
249+
def test_delta_astype(store: StorePath):
250+
data = np.linspace(0, 10, 256, dtype="i8").reshape((16, 16))
251+
252+
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
253+
a = Array.create(
254+
store / "generic",
255+
shape=data.shape,
256+
chunk_shape=(16, 16),
257+
dtype=data.dtype,
258+
fill_value=0,
259+
codecs=[
260+
numcodecs.zarr3.Delta(dtype="i8", astype="i2"), # type: ignore[arg-type]
261+
BytesCodec(),
262+
],
263+
)
264+
265+
a[:, :] = data.copy()
266+
a = Array.open(store / "generic")
267+
np.testing.assert_array_equal(data, a[:, :])

numcodecs/zarr3.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,19 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Shuffle:
266266

267267

268268
# array-to-array codecs ("filters")
269-
Delta = _add_docstring(_make_array_array_codec("delta", "Delta"), "numcodecs.delta.Delta")
269+
@_add_docstring_wrapper("numcodecs.delta.Delta")
270+
class Delta(_NumcodecsArrayArrayCodec):
271+
codec_name = f"{CODEC_PREFIX}delta"
272+
273+
def __init__(self, **codec_config: dict[str, JSON]) -> None:
274+
super().__init__(**codec_config)
275+
276+
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
277+
if astype := self.codec_config.get("astype"):
278+
return replace(chunk_spec, dtype=np.dtype(astype)) # type: ignore[arg-type]
279+
return chunk_spec
280+
281+
270282
BitRound = _add_docstring(
271283
_make_array_array_codec("bitround", "BitRound"), "numcodecs.bitround.BitRound"
272284
)

0 commit comments

Comments
 (0)