Skip to content

Commit 19a383f

Browse files
slevangd-v-b
andauthored
fix: remove numcodecs off-spec warning (#3833)
* move warning into to_dict * remove warning entirely * changelog * changelog type --------- Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com>
1 parent ea13af5 commit 19a383f

File tree

5 files changed

+100
-139
lines changed

5 files changed

+100
-139
lines changed

changes/3833.misc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the warning that is emitted when any Numcodecs codec is instantiated.

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:
@@ -102,12 +100,6 @@ def __init__(self, **codec_config: JSON) -> None:
102100
) # pragma: no cover
103101

104102
object.__setattr__(self, "codec_config", codec_config)
105-
warn(
106-
"Numcodecs codecs are not in the Zarr version 3 specification and "
107-
"may not be supported by other zarr implementations.",
108-
category=ZarrUserWarning,
109-
stacklevel=2,
110-
)
111103

112104
@cached_property
113105
def _codec(self) -> Numcodec:

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: 2 additions & 8 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")
@@ -524,8 +520,7 @@ def test_migrate_incorrect_filter(local_store: LocalStore) -> None:
524520
fill_value=0,
525521
)
526522

527-
with pytest.warns(UserWarning, match=NUMCODECS_USER_WARNING):
528-
result = runner.invoke(cli.app, ["migrate", "v3", str(local_store.root)])
523+
result = runner.invoke(cli.app, ["migrate", "v3", str(local_store.root)])
529524

530525
assert result.exit_code == 1
531526
assert isinstance(result.exception, TypeError)
@@ -548,8 +543,7 @@ def test_migrate_incorrect_compressor(local_store: LocalStore) -> None:
548543
fill_value=0,
549544
)
550545

551-
with pytest.warns(UserWarning, match=NUMCODECS_USER_WARNING):
552-
result = runner.invoke(cli.app, ["migrate", "v3", str(local_store.root)])
546+
result = runner.invoke(cli.app, ["migrate", "v3", str(local_store.root)])
553547

554548
assert result.exit_code == 1
555549
assert isinstance(result.exception, TypeError)

0 commit comments

Comments
 (0)