Skip to content

Commit 1e66846

Browse files
slevangd-v-b
authored andcommitted
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 1c2efa6 commit 1e66846

7 files changed

Lines changed: 104 additions & 144 deletions

File tree

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:

src/zarr/core/array.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4383,9 +4383,7 @@ class ShardsConfigParam(TypedDict):
43834383
index_location: ShardingCodecIndexLocation | None
43844384

43854385

4386-
type ShardsLike = (
4387-
tuple[int, ...] | Sequence[Sequence[int]] | ShardsConfigParam | Literal["auto"]
4388-
)
4386+
type ShardsLike = tuple[int, ...] | Sequence[Sequence[int]] | ShardsConfigParam | Literal["auto"]
43894387

43904388

43914389
async def from_array(

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
@@ -31,8 +31,6 @@
3131

3232
runner = typer_testing.CliRunner()
3333

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

3735
def test_migrate_array(local_store: LocalStore) -> None:
3836
shape = (10, 10)
@@ -315,7 +313,6 @@ def test_migrate_compressor(
315313
assert np.all(zarr_array[:] == 1)
316314

317315

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

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

361358

362-
@pytest.mark.filterwarnings(f"ignore:{NUMCODECS_USER_WARNING}:UserWarning")
363359
def test_migrate_filter(local_store: LocalStore) -> None:
364360
filter_v2 = numcodecs.Delta(dtype="<u2", astype="<u2")
365361
filter_v3 = Delta(dtype="<u2", astype="<u2")
@@ -523,8 +519,7 @@ def test_migrate_incorrect_filter(local_store: LocalStore) -> None:
523519
fill_value=0,
524520
)
525521

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

529524
assert result.exit_code == 1
530525
assert isinstance(result.exception, TypeError)
@@ -547,8 +542,7 @@ def test_migrate_incorrect_compressor(local_store: LocalStore) -> None:
547542
fill_value=0,
548543
)
549544

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

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

tests/test_codec_pipeline.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
import zarr
6+
from zarr.core.array import _get_chunk_spec
67
from zarr.core.buffer.core import default_buffer_prototype
78
from zarr.core.indexing import BasicIndexer
89
from zarr.storage import MemoryStore
@@ -42,7 +43,7 @@ async def test_read_returns_get_results(
4243
indexer = BasicIndexer(
4344
read_slice,
4445
shape=metadata.shape,
45-
chunk_grid=metadata.chunk_grid,
46+
chunk_grid=async_arr.chunk_grid,
4647
)
4748

4849
out_buffer = prototype.nd_buffer.empty(
@@ -55,7 +56,7 @@ async def test_read_returns_get_results(
5556
[
5657
(
5758
async_arr.store_path / metadata.encode_chunk_key(chunk_coords),
58-
metadata.get_chunk_spec(chunk_coords, config, prototype=prototype),
59+
_get_chunk_spec(metadata, async_arr.chunk_grid, chunk_coords, config, prototype),
5960
chunk_selection,
6061
out_selection,
6162
is_complete_chunk,

0 commit comments

Comments
 (0)