Skip to content

Commit 76ed82d

Browse files
committed
remove warning entirely
1 parent 05d28b1 commit 76ed82d

4 files changed

Lines changed: 80 additions & 136 deletions

File tree

src/zarr/codecs/numcodecs/_codecs.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from dataclasses import dataclass, replace
3333
from functools import cached_property
3434
from typing import TYPE_CHECKING, Any, Self
35-
from warnings import warn
3635

3736
import numpy as np
3837

@@ -41,7 +40,6 @@
4140
from zarr.core.buffer.cpu import as_numpy_array_wrapper
4241
from zarr.core.common import JSON, parse_named_configuration, product
4342
from zarr.dtype import UInt8, ZDType, parse_dtype
44-
from zarr.errors import ZarrUserWarning
4543
from zarr.registry import get_numcodec
4644

4745
if TYPE_CHECKING:
@@ -113,12 +111,6 @@ def from_dict(cls, data: dict[str, JSON]) -> Self:
113111
return cls(**codec_config)
114112

115113
def to_dict(self) -> dict[str, JSON]:
116-
warn(
117-
"Numcodecs codecs are not in the Zarr version 3 specification and "
118-
"may not be supported by other zarr implementations.",
119-
category=ZarrUserWarning,
120-
stacklevel=2,
121-
)
122114
codec_config = self.codec_config.copy()
123115
codec_config.pop("id", None)
124116
return {

tests/test_array.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,24 +1853,21 @@ def test_roundtrip_numcodecs() -> None:
18531853

18541854
# Create the array with the correct codecs
18551855
root = zarr.group(store)
1856-
warn_msg = "Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations."
1857-
with pytest.warns(ZarrUserWarning, match=warn_msg):
1858-
root.create_array(
1859-
"test",
1860-
shape=(720, 1440),
1861-
chunks=(720, 1440),
1862-
dtype="float64",
1863-
compressors=compressors, # type: ignore[arg-type]
1864-
filters=filters, # type: ignore[arg-type]
1865-
fill_value=-9.99,
1866-
dimension_names=["lat", "lon"],
1867-
)
1856+
root.create_array(
1857+
"test",
1858+
shape=(720, 1440),
1859+
chunks=(720, 1440),
1860+
dtype="float64",
1861+
compressors=compressors, # type: ignore[arg-type]
1862+
filters=filters, # type: ignore[arg-type]
1863+
fill_value=-9.99,
1864+
dimension_names=["lat", "lon"],
1865+
)
18681866

18691867
BYTES_CODEC = {"name": "bytes", "configuration": {"endian": "little"}}
18701868
# Read in the array again and check compressor config
18711869
root = zarr.open_group(store)
1872-
with pytest.warns(ZarrUserWarning, match=warn_msg):
1873-
metadata = root["test"].metadata.to_dict()
1870+
metadata = root["test"].metadata.to_dict()
18741871
expected = (*filters, BYTES_CODEC, *compressors)
18751872
assert metadata["codecs"] == expected
18761873

tests/test_cli/test_migrate_v3.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
runner = typer_testing.CliRunner()
3434

35-
NUMCODECS_USER_WARNING = "Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations."
36-
3735

3836
def test_migrate_array(local_store: LocalStore) -> None:
3937
shape = (10, 10)
@@ -316,7 +314,6 @@ def test_migrate_compressor(
316314
assert np.all(zarr_array[:] == 1)
317315

318316

319-
@pytest.mark.filterwarnings(f"ignore:{NUMCODECS_USER_WARNING}:UserWarning")
320317
def test_migrate_numcodecs_compressor(local_store: LocalStore) -> None:
321318
"""Test migration of a numcodecs compressor without a zarr.codecs equivalent."""
322319

@@ -360,7 +357,6 @@ def test_migrate_numcodecs_compressor(local_store: LocalStore) -> None:
360357
assert np.all(zarr_array[:] == 1)
361358

362359

363-
@pytest.mark.filterwarnings(f"ignore:{NUMCODECS_USER_WARNING}:UserWarning")
364360
def test_migrate_filter(local_store: LocalStore) -> None:
365361
filter_v2 = numcodecs.Delta(dtype="<u2", astype="<u2")
366362
filter_v3 = Delta(dtype="<u2", astype="<u2")

tests/test_codecs/test_numcodecs.py

Lines changed: 69 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import contextlib
44
import pickle
5-
import warnings
65
from typing import TYPE_CHECKING, Any
76

87
import numpy as np
@@ -18,7 +17,6 @@
1817
from zarr import config, create_array, open_array
1918
from zarr.abc.numcodec import _is_numcodec, _is_numcodec_cls
2019
from zarr.codecs import numcodecs as _numcodecs
21-
from zarr.errors import ZarrUserWarning
2220
from zarr.registry import get_codec_class, get_numcodec
2321

2422
if TYPE_CHECKING:
@@ -77,8 +75,6 @@ def test_is_numcodec_cls() -> None:
7775
assert _is_numcodec_cls(GZip)
7876

7977

80-
EXPECTED_WARNING_STR = "Numcodecs codecs are not in the Zarr version 3.*"
81-
8278
ALL_CODECS = tuple(
8379
filter(
8480
lambda v: issubclass(v, _numcodecs._NumcodecsCodec) and hasattr(v, "codec_name"),
@@ -116,15 +112,14 @@ def test_docstring(codec_class: type[_numcodecs._NumcodecsCodec]) -> None:
116112
def test_generic_compressor(codec_class: type[_numcodecs._NumcodecsBytesBytesCodec]) -> None:
117113
data = np.arange(0, 256, dtype="uint16").reshape((16, 16))
118114

119-
with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR):
120-
a = create_array(
121-
{},
122-
shape=data.shape,
123-
chunks=(16, 16),
124-
dtype=data.dtype,
125-
fill_value=0,
126-
compressors=[codec_class()],
127-
)
115+
a = create_array(
116+
{},
117+
shape=data.shape,
118+
chunks=(16, 16),
119+
dtype=data.dtype,
120+
fill_value=0,
121+
compressors=[codec_class()],
122+
)
128123

129124
a[:, :] = data.copy()
130125
np.testing.assert_array_equal(data, a[:, :])
@@ -151,17 +146,16 @@ def test_generic_filter(
151146
) -> None:
152147
data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16))
153148

154-
with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR):
155-
a = create_array(
156-
{},
157-
shape=data.shape,
158-
chunks=(16, 16),
159-
dtype=data.dtype,
160-
fill_value=0,
161-
filters=[
162-
codec_class(**codec_config),
163-
],
164-
)
149+
a = create_array(
150+
{},
151+
shape=data.shape,
152+
chunks=(16, 16),
153+
dtype=data.dtype,
154+
fill_value=0,
155+
filters=[
156+
codec_class(**codec_config),
157+
],
158+
)
165159

166160
a[:, :] = data.copy()
167161
with codec_conf():
@@ -172,15 +166,14 @@ def test_generic_filter(
172166
def test_generic_filter_bitround() -> None:
173167
data = np.linspace(0, 1, 256, dtype="float32").reshape((16, 16))
174168

175-
with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR):
176-
a = create_array(
177-
{},
178-
shape=data.shape,
179-
chunks=(16, 16),
180-
dtype=data.dtype,
181-
fill_value=0,
182-
filters=[_numcodecs.BitRound(keepbits=3)],
183-
)
169+
a = create_array(
170+
{},
171+
shape=data.shape,
172+
chunks=(16, 16),
173+
dtype=data.dtype,
174+
fill_value=0,
175+
filters=[_numcodecs.BitRound(keepbits=3)],
176+
)
184177

185178
a[:, :] = data.copy()
186179
b = open_array(a.store, mode="r")
@@ -190,15 +183,14 @@ def test_generic_filter_bitround() -> None:
190183
def test_generic_filter_quantize() -> None:
191184
data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16))
192185

193-
with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR):
194-
a = create_array(
195-
{},
196-
shape=data.shape,
197-
chunks=(16, 16),
198-
dtype=data.dtype,
199-
fill_value=0,
200-
filters=[_numcodecs.Quantize(digits=3)],
201-
)
186+
a = create_array(
187+
{},
188+
shape=data.shape,
189+
chunks=(16, 16),
190+
dtype=data.dtype,
191+
fill_value=0,
192+
filters=[_numcodecs.Quantize(digits=3)],
193+
)
202194

203195
a[:, :] = data.copy()
204196
b = open_array(a.store, mode="r")
@@ -209,15 +201,14 @@ def test_generic_filter_packbits() -> None:
209201
data = np.zeros((16, 16), dtype="bool")
210202
data[0:4, :] = True
211203

212-
with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR):
213-
a = create_array(
214-
{},
215-
shape=data.shape,
216-
chunks=(16, 16),
217-
dtype=data.dtype,
218-
fill_value=0,
219-
filters=[_numcodecs.PackBits()],
220-
)
204+
a = create_array(
205+
{},
206+
shape=data.shape,
207+
chunks=(16, 16),
208+
dtype=data.dtype,
209+
fill_value=0,
210+
filters=[_numcodecs.PackBits()],
211+
)
221212

222213
a[:, :] = data.copy()
223214
b = open_array(a.store, mode="r")
@@ -253,15 +244,14 @@ def test_generic_checksum(codec_class: type[_numcodecs._NumcodecsBytesBytesCodec
253244

254245
data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16))
255246

256-
with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR):
257-
a = create_array(
258-
{},
259-
shape=data.shape,
260-
chunks=(16, 16),
261-
dtype=data.dtype,
262-
fill_value=0,
263-
compressors=[codec_class()],
264-
)
247+
a = create_array(
248+
{},
249+
shape=data.shape,
250+
chunks=(16, 16),
251+
dtype=data.dtype,
252+
fill_value=0,
253+
compressors=[codec_class()],
254+
)
265255

266256
a[:, :] = data.copy()
267257
with codec_conf():
@@ -283,15 +273,14 @@ def test_generic_bytes_codec(codec_class: type[_numcodecs._NumcodecsArrayBytesCo
283273

284274
data = np.arange(0, 256, dtype="float32").reshape((16, 16))
285275

286-
with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR):
287-
a = create_array(
288-
{},
289-
shape=data.shape,
290-
chunks=(16, 16),
291-
dtype=data.dtype,
292-
fill_value=0,
293-
serializer=codec_class(),
294-
)
276+
a = create_array(
277+
{},
278+
shape=data.shape,
279+
chunks=(16, 16),
280+
dtype=data.dtype,
281+
fill_value=0,
282+
serializer=codec_class(),
283+
)
295284

296285
a[:, :] = data.copy()
297286
np.testing.assert_array_equal(data, a[:, :])
@@ -300,17 +289,16 @@ def test_generic_bytes_codec(codec_class: type[_numcodecs._NumcodecsArrayBytesCo
300289
def test_delta_astype() -> None:
301290
data = np.linspace(0, 10, 256, dtype="i8").reshape((16, 16))
302291

303-
with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR):
304-
a = create_array(
305-
{},
306-
shape=data.shape,
307-
chunks=(16, 16),
308-
dtype=data.dtype,
309-
fill_value=0,
310-
filters=[
311-
_numcodecs.Delta(dtype="i8", astype="i2"),
312-
],
313-
)
292+
a = create_array(
293+
{},
294+
shape=data.shape,
295+
chunks=(16, 16),
296+
dtype=data.dtype,
297+
fill_value=0,
298+
filters=[
299+
_numcodecs.Delta(dtype="i8", astype="i2"),
300+
],
301+
)
314302

315303
a[:, :] = data.copy()
316304
with codec_conf():
@@ -325,36 +313,7 @@ def test_repr() -> None:
325313

326314
def test_to_dict() -> None:
327315
codec = _numcodecs.LZ4(level=5)
328-
with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR):
329-
assert codec.to_dict() == {"name": "numcodecs.lz4", "configuration": {"level": 5}}
330-
331-
332-
def test_warn_on_write_not_read() -> None:
333-
data = np.arange(0, 256, dtype="uint16").reshape((16, 16))
334-
335-
with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR):
336-
a = create_array(
337-
{},
338-
shape=data.shape,
339-
chunks=(16, 16),
340-
dtype=data.dtype,
341-
fill_value=0,
342-
compressors=[_numcodecs.Zstd(level=1)],
343-
)
344-
345-
a[:, :] = data.copy()
346-
with codec_conf():
347-
with warnings.catch_warnings(record=True) as caught:
348-
warnings.simplefilter("always")
349-
b = open_array(a.store, mode="r")
350-
351-
np.testing.assert_array_equal(data, b[:, :])
352-
assert not [
353-
warning
354-
for warning in caught
355-
if issubclass(warning.category, ZarrUserWarning)
356-
and "Numcodecs codecs are not in the Zarr version 3 specification" in str(warning.message)
357-
]
316+
assert codec.to_dict() == {"name": "numcodecs.lz4", "configuration": {"level": 5}}
358317

359318

360319
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)