diff --git a/changes/3833.misc.md b/changes/3833.misc.md new file mode 100644 index 0000000000..1f3c87b482 --- /dev/null +++ b/changes/3833.misc.md @@ -0,0 +1 @@ +Remove the warning that is emitted when any Numcodecs codec is instantiated. diff --git a/src/zarr/codecs/numcodecs/_codecs.py b/src/zarr/codecs/numcodecs/_codecs.py index 4a3d88a84f..06c085ad2a 100644 --- a/src/zarr/codecs/numcodecs/_codecs.py +++ b/src/zarr/codecs/numcodecs/_codecs.py @@ -32,7 +32,6 @@ from dataclasses import dataclass, replace from functools import cached_property from typing import TYPE_CHECKING, Any, Self -from warnings import warn import numpy as np @@ -41,7 +40,6 @@ from zarr.core.buffer.cpu import as_numpy_array_wrapper from zarr.core.common import JSON, parse_named_configuration, product from zarr.dtype import UInt8, ZDType, parse_dtype -from zarr.errors import ZarrUserWarning from zarr.registry import get_numcodec if TYPE_CHECKING: @@ -102,12 +100,6 @@ def __init__(self, **codec_config: JSON) -> None: ) # pragma: no cover object.__setattr__(self, "codec_config", codec_config) - warn( - "Numcodecs codecs are not in the Zarr version 3 specification and " - "may not be supported by other zarr implementations.", - category=ZarrUserWarning, - stacklevel=2, - ) @cached_property def _codec(self) -> Numcodec: diff --git a/tests/test_array.py b/tests/test_array.py index 8ea79b5f10..bf6f651283 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -1853,24 +1853,21 @@ def test_roundtrip_numcodecs() -> None: # Create the array with the correct codecs root = zarr.group(store) - warn_msg = "Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations." - with pytest.warns(ZarrUserWarning, match=warn_msg): - root.create_array( - "test", - shape=(720, 1440), - chunks=(720, 1440), - dtype="float64", - compressors=compressors, # type: ignore[arg-type] - filters=filters, # type: ignore[arg-type] - fill_value=-9.99, - dimension_names=["lat", "lon"], - ) + root.create_array( + "test", + shape=(720, 1440), + chunks=(720, 1440), + dtype="float64", + compressors=compressors, # type: ignore[arg-type] + filters=filters, # type: ignore[arg-type] + fill_value=-9.99, + dimension_names=["lat", "lon"], + ) BYTES_CODEC = {"name": "bytes", "configuration": {"endian": "little"}} # Read in the array again and check compressor config root = zarr.open_group(store) - with pytest.warns(ZarrUserWarning, match=warn_msg): - metadata = root["test"].metadata.to_dict() + metadata = root["test"].metadata.to_dict() expected = (*filters, BYTES_CODEC, *compressors) assert metadata["codecs"] == expected diff --git a/tests/test_cli/test_migrate_v3.py b/tests/test_cli/test_migrate_v3.py index 8bda31d208..6e169e5f48 100644 --- a/tests/test_cli/test_migrate_v3.py +++ b/tests/test_cli/test_migrate_v3.py @@ -32,8 +32,6 @@ runner = typer_testing.CliRunner() -NUMCODECS_USER_WARNING = "Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations." - def test_migrate_array(local_store: LocalStore) -> None: shape = (10, 10) @@ -316,7 +314,6 @@ def test_migrate_compressor( assert np.all(zarr_array[:] == 1) -@pytest.mark.filterwarnings(f"ignore:{NUMCODECS_USER_WARNING}:UserWarning") def test_migrate_numcodecs_compressor(local_store: LocalStore) -> None: """Test migration of a numcodecs compressor without a zarr.codecs equivalent.""" @@ -360,7 +357,6 @@ def test_migrate_numcodecs_compressor(local_store: LocalStore) -> None: assert np.all(zarr_array[:] == 1) -@pytest.mark.filterwarnings(f"ignore:{NUMCODECS_USER_WARNING}:UserWarning") def test_migrate_filter(local_store: LocalStore) -> None: filter_v2 = numcodecs.Delta(dtype=" None: fill_value=0, ) - with pytest.warns(UserWarning, match=NUMCODECS_USER_WARNING): - result = runner.invoke(cli.app, ["migrate", "v3", str(local_store.root)]) + result = runner.invoke(cli.app, ["migrate", "v3", str(local_store.root)]) assert result.exit_code == 1 assert isinstance(result.exception, TypeError) @@ -548,8 +543,7 @@ def test_migrate_incorrect_compressor(local_store: LocalStore) -> None: fill_value=0, ) - with pytest.warns(UserWarning, match=NUMCODECS_USER_WARNING): - result = runner.invoke(cli.app, ["migrate", "v3", str(local_store.root)]) + result = runner.invoke(cli.app, ["migrate", "v3", str(local_store.root)]) assert result.exit_code == 1 assert isinstance(result.exception, TypeError) diff --git a/tests/test_codecs/test_numcodecs.py b/tests/test_codecs/test_numcodecs.py index ddfca71294..eec0ecacae 100644 --- a/tests/test_codecs/test_numcodecs.py +++ b/tests/test_codecs/test_numcodecs.py @@ -17,7 +17,6 @@ from zarr import config, create_array, open_array from zarr.abc.numcodec import _is_numcodec, _is_numcodec_cls from zarr.codecs import numcodecs as _numcodecs -from zarr.errors import ZarrUserWarning from zarr.registry import get_codec_class, get_numcodec if TYPE_CHECKING: @@ -76,8 +75,6 @@ def test_is_numcodec_cls() -> None: assert _is_numcodec_cls(GZip) -EXPECTED_WARNING_STR = "Numcodecs codecs are not in the Zarr version 3.*" - ALL_CODECS = tuple( filter( lambda v: issubclass(v, _numcodecs._NumcodecsCodec) and hasattr(v, "codec_name"), @@ -115,15 +112,14 @@ def test_docstring(codec_class: type[_numcodecs._NumcodecsCodec]) -> None: def test_generic_compressor(codec_class: type[_numcodecs._NumcodecsBytesBytesCodec]) -> None: data = np.arange(0, 256, dtype="uint16").reshape((16, 16)) - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - a = create_array( - {}, - shape=data.shape, - chunks=(16, 16), - dtype=data.dtype, - fill_value=0, - compressors=[codec_class()], - ) + a = create_array( + {}, + shape=data.shape, + chunks=(16, 16), + dtype=data.dtype, + fill_value=0, + compressors=[codec_class()], + ) a[:, :] = data.copy() np.testing.assert_array_equal(data, a[:, :]) @@ -150,60 +146,54 @@ def test_generic_filter( ) -> None: data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16)) - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - a = create_array( - {}, - shape=data.shape, - chunks=(16, 16), - dtype=data.dtype, - fill_value=0, - filters=[ - codec_class(**codec_config), - ], - ) + a = create_array( + {}, + shape=data.shape, + chunks=(16, 16), + dtype=data.dtype, + fill_value=0, + filters=[ + codec_class(**codec_config), + ], + ) a[:, :] = data.copy() with codec_conf(): - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - b = open_array(a.store, mode="r") + b = open_array(a.store, mode="r") np.testing.assert_array_equal(data, b[:, :]) def test_generic_filter_bitround() -> None: data = np.linspace(0, 1, 256, dtype="float32").reshape((16, 16)) - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - a = create_array( - {}, - shape=data.shape, - chunks=(16, 16), - dtype=data.dtype, - fill_value=0, - filters=[_numcodecs.BitRound(keepbits=3)], - ) + a = create_array( + {}, + shape=data.shape, + chunks=(16, 16), + dtype=data.dtype, + fill_value=0, + filters=[_numcodecs.BitRound(keepbits=3)], + ) a[:, :] = data.copy() - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - b = open_array(a.store, mode="r") + b = open_array(a.store, mode="r") assert np.allclose(data, b[:, :], atol=0.1) def test_generic_filter_quantize() -> None: data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16)) - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - a = create_array( - {}, - shape=data.shape, - chunks=(16, 16), - dtype=data.dtype, - fill_value=0, - filters=[_numcodecs.Quantize(digits=3)], - ) + a = create_array( + {}, + shape=data.shape, + chunks=(16, 16), + dtype=data.dtype, + fill_value=0, + filters=[_numcodecs.Quantize(digits=3)], + ) a[:, :] = data.copy() - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - b = open_array(a.store, mode="r") + b = open_array(a.store, mode="r") assert np.allclose(data, b[:, :], atol=0.001) @@ -211,32 +201,29 @@ def test_generic_filter_packbits() -> None: data = np.zeros((16, 16), dtype="bool") data[0:4, :] = True - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - a = create_array( + a = create_array( + {}, + shape=data.shape, + chunks=(16, 16), + dtype=data.dtype, + fill_value=0, + filters=[_numcodecs.PackBits()], + ) + + a[:, :] = data.copy() + b = open_array(a.store, mode="r") + np.testing.assert_array_equal(data, b[:, :]) + + with pytest.raises(ValueError, match=".*requires bool dtype.*"): + create_array( {}, shape=data.shape, chunks=(16, 16), - dtype=data.dtype, + dtype="uint32", fill_value=0, filters=[_numcodecs.PackBits()], ) - a[:, :] = data.copy() - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - b = open_array(a.store, mode="r") - np.testing.assert_array_equal(data, b[:, :]) - - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - with pytest.raises(ValueError, match=".*requires bool dtype.*"): - create_array( - {}, - shape=data.shape, - chunks=(16, 16), - dtype="uint32", - fill_value=0, - filters=[_numcodecs.PackBits()], - ) - @pytest.mark.parametrize( "codec_class", @@ -251,35 +238,31 @@ def test_generic_filter_packbits() -> None: def test_generic_checksum(codec_class: type[_numcodecs._NumcodecsBytesBytesCodec]) -> None: # Check if the codec is available in numcodecs try: - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - codec_class()._codec # noqa: B018 + codec_class()._codec # noqa: B018 except UnknownCodecError as e: # pragma: no cover pytest.skip(f"{codec_class.codec_name} is not available in numcodecs: {e}") data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16)) - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - a = create_array( - {}, - shape=data.shape, - chunks=(16, 16), - dtype=data.dtype, - fill_value=0, - compressors=[codec_class()], - ) + a = create_array( + {}, + shape=data.shape, + chunks=(16, 16), + dtype=data.dtype, + fill_value=0, + compressors=[codec_class()], + ) a[:, :] = data.copy() with codec_conf(): - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - b = open_array(a.store, mode="r") + b = open_array(a.store, mode="r") np.testing.assert_array_equal(data, b[:, :]) @pytest.mark.parametrize("codec_class", [_numcodecs.PCodec, _numcodecs.ZFPY]) def test_generic_bytes_codec(codec_class: type[_numcodecs._NumcodecsArrayBytesCodec]) -> None: try: - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - codec_class()._codec # noqa: B018 + codec_class()._codec # noqa: B018 except ValueError as e: # pragma: no cover if "codec not available" in str(e): pytest.xfail(f"{codec_class.codec_name} is not available: {e}") @@ -290,15 +273,14 @@ def test_generic_bytes_codec(codec_class: type[_numcodecs._NumcodecsArrayBytesCo data = np.arange(0, 256, dtype="float32").reshape((16, 16)) - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - a = create_array( - {}, - shape=data.shape, - chunks=(16, 16), - dtype=data.dtype, - fill_value=0, - serializer=codec_class(), - ) + a = create_array( + {}, + shape=data.shape, + chunks=(16, 16), + dtype=data.dtype, + fill_value=0, + serializer=codec_class(), + ) a[:, :] = data.copy() np.testing.assert_array_equal(data, a[:, :]) @@ -307,34 +289,30 @@ def test_generic_bytes_codec(codec_class: type[_numcodecs._NumcodecsArrayBytesCo def test_delta_astype() -> None: data = np.linspace(0, 10, 256, dtype="i8").reshape((16, 16)) - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - a = create_array( - {}, - shape=data.shape, - chunks=(16, 16), - dtype=data.dtype, - fill_value=0, - filters=[ - _numcodecs.Delta(dtype="i8", astype="i2"), - ], - ) + a = create_array( + {}, + shape=data.shape, + chunks=(16, 16), + dtype=data.dtype, + fill_value=0, + filters=[ + _numcodecs.Delta(dtype="i8", astype="i2"), + ], + ) a[:, :] = data.copy() with codec_conf(): - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - b = open_array(a.store, mode="r") + b = open_array(a.store, mode="r") np.testing.assert_array_equal(data, b[:, :]) def test_repr() -> None: - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - codec = _numcodecs.LZ4(level=5) + codec = _numcodecs.LZ4(level=5) assert repr(codec) == "LZ4(codec_name='numcodecs.lz4', codec_config={'level': 5})" def test_to_dict() -> None: - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - codec = _numcodecs.LZ4(level=5) + codec = _numcodecs.LZ4(level=5) assert codec.to_dict() == {"name": "numcodecs.lz4", "configuration": {"level": 5}} @@ -367,8 +345,7 @@ def test_to_dict() -> None: def test_codecs_pickleable(codec_cls: type[_numcodecs._NumcodecsCodec]) -> None: # Check if the codec is available in numcodecs try: - with pytest.warns(ZarrUserWarning, match=EXPECTED_WARNING_STR): - codec = codec_cls() + codec = codec_cls() except UnknownCodecError as e: # pragma: no cover pytest.skip(f"{codec_cls.codec_name} is not available in numcodecs: {e}")