From 79560d5b80fed1187376b9f3a710ddc9c94b3af2 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sat, 15 Feb 2025 22:20:15 +0100 Subject: [PATCH 01/11] fix merge --- tests/test_array.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/test_array.py b/tests/test_array.py index b81f966e20..c8f3b08676 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -35,7 +35,7 @@ _parse_chunk_encoding_v2, _parse_chunk_encoding_v3, chunks_initialized, - create_array, + create_array, SerializerLike, ) from zarr.core.buffer import default_buffer_prototype from zarr.core.buffer.cpu import NDBuffer @@ -1025,6 +1025,14 @@ async def test_no_filters_compressors(store: MemoryStore, dtype: str, empty_valu ZstdCodec(level=3), {"name": "zstd", "configuration": {"level": 3}}, ({"name": "zstd", "configuration": {"level": 3}},), + "zstd", + ], + ) + @pytest.mark.parametrize( + "serializer", + [ + "auto", + "bytes", ], ) @pytest.mark.parametrize( @@ -1059,12 +1067,15 @@ async def test_no_filters_compressors(store: MemoryStore, dtype: str, empty_valu ), {"name": "transpose", "configuration": {"order": [0]}}, ({"name": "transpose", "configuration": {"order": [0]}},), + "transpose", ], ) + @pytest.mark.parametrize(("chunks", "shards"), [((6,), None), ((3,), (6,))]) async def test_v3_chunk_encoding( store: MemoryStore, compressors: CompressorsLike, + serializer: SerializerLike, filters: FiltersLike, dtype: str, chunks: tuple[int, ...], @@ -1081,10 +1092,11 @@ async def test_v3_chunk_encoding( shards=shards, zarr_format=3, filters=filters, + serializer=serializer, compressors=compressors, ) - filters_expected, _, compressors_expected = _parse_chunk_encoding_v3( - filters=filters, compressors=compressors, serializer="auto", dtype=np.dtype(dtype) + filters_expected, serializer_expected, compressors_expected = _parse_chunk_encoding_v3( + filters=filters, compressors=compressors, serializer=serializer, dtype=np.dtype(dtype) ) assert arr.filters == filters_expected assert arr.compressors == compressors_expected @@ -1099,10 +1111,11 @@ async def test_v3_chunk_encoding( numcodecs.Zstd(level=3), (), (numcodecs.Zstd(level=3),), + "zstd" ], ) @pytest.mark.parametrize( - "filters", ["auto", None, numcodecs.GZip(level=1), (numcodecs.GZip(level=1),)] + "filters", ["auto", None, numcodecs.GZip(level=1), (numcodecs.GZip(level=1),"gzip")] ) async def test_v2_chunk_encoding( store: MemoryStore, compressors: CompressorsLike, filters: FiltersLike, dtype: str From 76199904a5285e1d71619e4b4ee3033ed26a374e Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sat, 15 Feb 2025 23:27:04 +0100 Subject: [PATCH 02/11] add str arguments for filters, serializer, compressors --- src/zarr/core/array.py | 12 +++++++++--- src/zarr/core/metadata/v2.py | 12 +++++++++--- src/zarr/registry.py | 12 +++++++++--- tests/test_array.py | 22 +++++++++++++++++----- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index 9c2f8a7260..7ab61a4e7c 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -3769,23 +3769,25 @@ def _get_default_codecs( FiltersLike: TypeAlias = ( - Iterable[dict[str, JSON] | ArrayArrayCodec | numcodecs.abc.Codec] + Iterable[dict[str, JSON] | str | ArrayArrayCodec | numcodecs.abc.Codec] | ArrayArrayCodec | Iterable[numcodecs.abc.Codec] | numcodecs.abc.Codec | Literal["auto"] + | str | None ) CompressorLike: TypeAlias = dict[str, JSON] | BytesBytesCodec | numcodecs.abc.Codec | None CompressorsLike: TypeAlias = ( - Iterable[dict[str, JSON] | BytesBytesCodec | numcodecs.abc.Codec] + Iterable[dict[str, JSON] | str | BytesBytesCodec | numcodecs.abc.Codec] | dict[str, JSON] | BytesBytesCodec | numcodecs.abc.Codec | Literal["auto"] + | str | None ) -SerializerLike: TypeAlias = dict[str, JSON] | ArrayBytesCodec | Literal["auto"] +SerializerLike: TypeAlias = dict[str, JSON] | ArrayBytesCodec | Literal["auto"] | str class ShardsConfigParam(TypedDict): @@ -4305,6 +4307,8 @@ def _parse_chunk_encoding_v3( out_array_array: tuple[ArrayArrayCodec, ...] = () elif filters == "auto": out_array_array = default_array_array + elif isinstance(filters, str): + out_array_array = (_parse_array_array_codec(filters),) else: maybe_array_array: Iterable[Codec | dict[str, JSON]] if isinstance(filters, dict | Codec): @@ -4322,6 +4326,8 @@ def _parse_chunk_encoding_v3( out_bytes_bytes: tuple[BytesBytesCodec, ...] = () elif compressors == "auto": out_bytes_bytes = default_bytes_bytes + elif isinstance(compressors, str): + out_bytes_bytes = (_parse_bytes_bytes_codec(compressors),) else: maybe_bytes_bytes: Iterable[Codec | dict[str, JSON]] if isinstance(compressors, dict | Codec): diff --git a/src/zarr/core/metadata/v2.py b/src/zarr/core/metadata/v2.py index 3d292c81b4..c1e87aa3e0 100644 --- a/src/zarr/core/metadata/v2.py +++ b/src/zarr/core/metadata/v2.py @@ -246,20 +246,24 @@ def parse_filters(data: object) -> tuple[numcodecs.abc.Codec, ...] | None: if data is None: return data + if isinstance(data, str): + return (numcodecs.get_codec({"id": data}),) if isinstance(data, Iterable): for idx, val in enumerate(data): if isinstance(val, numcodecs.abc.Codec): out.append(val) elif isinstance(val, dict): out.append(numcodecs.get_codec(val)) + elif isinstance(val, str): + out.append(numcodecs.get_codec({"id": val})) else: - msg = f"Invalid filter at index {idx}. Expected a numcodecs.abc.Codec or a dict representation of numcodecs.abc.Codec. Got {type(val)} instead." + msg = f"For Zarr format 2 arrays, all elements of `filters` must be a numcodecs.abc.Codec or a dict or str representation of numcodecs.abc.Codec. Got {type(val)} at index {idx} instead." raise TypeError(msg) return tuple(out) # take a single codec instance and wrap it in a tuple if isinstance(data, numcodecs.abc.Codec): return (data,) - msg = f"Invalid filters. Expected None, an iterable of numcodecs.abc.Codec or dict representations of numcodecs.abc.Codec. Got {type(data)} instead." + msg = f"For Zarr format 2 arrays, all elements of `filters` must be None, an iterable of numcodecs.abc.Codec or dict representations of numcodecs.abc.Codec. Got {type(data)} instead." raise TypeError(msg) @@ -271,7 +275,9 @@ def parse_compressor(data: object) -> numcodecs.abc.Codec | None: return data if isinstance(data, dict): return numcodecs.get_codec(data) - msg = f"Invalid compressor. Expected None, a numcodecs.abc.Codec, or a dict representation of a numcodecs.abc.Codec. Got {type(data)} instead." + if isinstance(data, str): + return numcodecs.get_codec({"id": data}) + msg = f"For Zarr format 2 arrays, the `compressor` must be a single codec. Expected None, a numcodecs.abc.Codec, or a dict or str representation of a numcodecs.abc.Codec. Got {type(data)} instead." raise ValueError(msg) diff --git a/src/zarr/registry.py b/src/zarr/registry.py index 704db3f704..72fd6de85c 100644 --- a/src/zarr/registry.py +++ b/src/zarr/registry.py @@ -166,7 +166,7 @@ def _resolve_codec(data: dict[str, JSON]) -> Codec: return get_codec_class(data["name"]).from_dict(data) # type: ignore[arg-type] -def _parse_bytes_bytes_codec(data: dict[str, JSON] | Codec) -> BytesBytesCodec: +def _parse_bytes_bytes_codec(data: dict[str, JSON] | str | Codec) -> BytesBytesCodec: """ Normalize the input to a ``BytesBytesCodec`` instance. If the input is already a ``BytesBytesCodec``, it is returned as is. If the input is a dict, it @@ -174,6 +174,8 @@ def _parse_bytes_bytes_codec(data: dict[str, JSON] | Codec) -> BytesBytesCodec: """ from zarr.abc.codec import BytesBytesCodec + if isinstance(data, str): + data = {"name": data, "configuration": {}} if isinstance(data, dict): result = _resolve_codec(data) if not isinstance(result, BytesBytesCodec): @@ -186,7 +188,7 @@ def _parse_bytes_bytes_codec(data: dict[str, JSON] | Codec) -> BytesBytesCodec: return result -def _parse_array_bytes_codec(data: dict[str, JSON] | Codec) -> ArrayBytesCodec: +def _parse_array_bytes_codec(data: dict[str, JSON] | str | Codec) -> ArrayBytesCodec: """ Normalize the input to a ``ArrayBytesCodec`` instance. If the input is already a ``ArrayBytesCodec``, it is returned as is. If the input is a dict, it @@ -194,6 +196,8 @@ def _parse_array_bytes_codec(data: dict[str, JSON] | Codec) -> ArrayBytesCodec: """ from zarr.abc.codec import ArrayBytesCodec + if isinstance(data, str): + data = {"name": data, "configuration": {}} if isinstance(data, dict): result = _resolve_codec(data) if not isinstance(result, ArrayBytesCodec): @@ -206,7 +210,7 @@ def _parse_array_bytes_codec(data: dict[str, JSON] | Codec) -> ArrayBytesCodec: return result -def _parse_array_array_codec(data: dict[str, JSON] | Codec) -> ArrayArrayCodec: +def _parse_array_array_codec(data: dict[str, JSON] | str | Codec) -> ArrayArrayCodec: """ Normalize the input to a ``ArrayArrayCodec`` instance. If the input is already a ``ArrayArrayCodec``, it is returned as is. If the input is a dict, it @@ -214,6 +218,8 @@ def _parse_array_array_codec(data: dict[str, JSON] | Codec) -> ArrayArrayCodec: """ from zarr.abc.codec import ArrayArrayCodec + if isinstance(data, str): + data = {"name": data, "configuration": {}} if isinstance(data, dict): result = _resolve_codec(data) if not isinstance(result, ArrayArrayCodec): diff --git a/tests/test_array.py b/tests/test_array.py index c8f3b08676..8522bcc7e7 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -30,12 +30,13 @@ from zarr.core.array import ( CompressorsLike, FiltersLike, + SerializerLike, _get_default_chunk_encoding_v2, _get_default_chunk_encoding_v3, _parse_chunk_encoding_v2, _parse_chunk_encoding_v3, chunks_initialized, - create_array, SerializerLike, + create_array, ) from zarr.core.buffer import default_buffer_prototype from zarr.core.buffer.cpu import NDBuffer @@ -1026,6 +1027,7 @@ async def test_no_filters_compressors(store: MemoryStore, dtype: str, empty_valu {"name": "zstd", "configuration": {"level": 3}}, ({"name": "zstd", "configuration": {"level": 3}},), "zstd", + ("crc32c", "zstd"), ], ) @pytest.mark.parametrize( @@ -1067,10 +1069,9 @@ async def test_no_filters_compressors(store: MemoryStore, dtype: str, empty_valu ), {"name": "transpose", "configuration": {"order": [0]}}, ({"name": "transpose", "configuration": {"order": [0]}},), - "transpose", + # is there a filter with no configuration? ], ) - @pytest.mark.parametrize(("chunks", "shards"), [((6,), None), ((3,), (6,))]) async def test_v3_chunk_encoding( store: MemoryStore, @@ -1084,6 +1085,9 @@ async def test_v3_chunk_encoding( """ Test various possibilities for the compressors and filters parameter to create_array """ + if serializer == "bytes" and dtype == "str": + serializer = "vlen-utf8" + arr = await create_array( store=store, dtype=dtype, @@ -1111,11 +1115,19 @@ async def test_v3_chunk_encoding( numcodecs.Zstd(level=3), (), (numcodecs.Zstd(level=3),), - "zstd" + "zstd", ], ) @pytest.mark.parametrize( - "filters", ["auto", None, numcodecs.GZip(level=1), (numcodecs.GZip(level=1),"gzip")] + "filters", + [ + "auto", + None, + numcodecs.GZip(level=1), + (numcodecs.GZip(level=1)), + "gzip", + ("gzip", "zstd"), + ], ) async def test_v2_chunk_encoding( store: MemoryStore, compressors: CompressorsLike, filters: FiltersLike, dtype: str From daff61abc1d61cbd348fee7b9449f5e2dc8e1349 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sat, 15 Feb 2025 23:27:29 +0100 Subject: [PATCH 03/11] remove duplicate type check --- src/zarr/core/array.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index 7ab61a4e7c..52871111fa 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -4266,9 +4266,6 @@ def _parse_chunk_encoding_v2( elif isinstance(compressor, tuple | list) and len(compressor) == 1: _compressor = parse_compressor(compressor[0]) else: - if isinstance(compressor, Iterable) and not isinstance(compressor, dict): - msg = f"For Zarr format 2 arrays, the `compressor` must be a single codec. Got an iterable with type {type(compressor)} instead." - raise TypeError(msg) _compressor = parse_compressor(compressor) if filters is None: @@ -4276,14 +4273,6 @@ def _parse_chunk_encoding_v2( elif filters == "auto": _filters = default_filters else: - if isinstance(filters, Iterable): - for idx, f in enumerate(filters): - if not isinstance(f, numcodecs.abc.Codec): - msg = ( - "For Zarr format 2 arrays, all elements of `filters` must be numcodecs codecs. " - f"Element at index {idx} has type {type(f)}, which is not a numcodecs codec." - ) - raise TypeError(msg) _filters = parse_filters(filters) return _filters, _compressor From 1a3a5027d18478fa3aa90595677cbec52817b982 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sat, 15 Feb 2025 23:35:58 +0100 Subject: [PATCH 04/11] fix ruff --- src/zarr/core/array.py | 4 +--- tests/test_array.py | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index 52871111fa..fe491a4cc8 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -3773,7 +3773,6 @@ def _get_default_codecs( | ArrayArrayCodec | Iterable[numcodecs.abc.Codec] | numcodecs.abc.Codec - | Literal["auto"] | str | None ) @@ -3783,11 +3782,10 @@ def _get_default_codecs( | dict[str, JSON] | BytesBytesCodec | numcodecs.abc.Codec - | Literal["auto"] | str | None ) -SerializerLike: TypeAlias = dict[str, JSON] | ArrayBytesCodec | Literal["auto"] | str +SerializerLike: TypeAlias = dict[str, JSON] | ArrayBytesCodec | str class ShardsConfigParam(TypedDict): diff --git a/tests/test_array.py b/tests/test_array.py index 8522bcc7e7..6df8cf581b 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -1114,7 +1114,7 @@ async def test_v3_chunk_encoding( None, numcodecs.Zstd(level=3), (), - (numcodecs.Zstd(level=3),), + (numcodecs.Zstd(level=2),), "zstd", ], ) @@ -1124,7 +1124,7 @@ async def test_v3_chunk_encoding( "auto", None, numcodecs.GZip(level=1), - (numcodecs.GZip(level=1)), + (numcodecs.GZip(level=2)), "gzip", ("gzip", "zstd"), ], From 68ac3299235e8e8344ed8bf2a37162c2e1214400 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sat, 15 Feb 2025 23:42:32 +0100 Subject: [PATCH 05/11] update docstrings --- src/zarr/api/synchronous.py | 2 +- src/zarr/core/array.py | 2 +- src/zarr/core/group.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/zarr/api/synchronous.py b/src/zarr/api/synchronous.py index e1f92633cd..48d8733b87 100644 --- a/src/zarr/api/synchronous.py +++ b/src/zarr/api/synchronous.py @@ -792,7 +792,7 @@ def create_array( chunk to bytes. For Zarr format 3, a "filter" is a codec that takes an array and returns an array, - and these values must be instances of ``ArrayArrayCodec``, or dict representations + and these values must be instances of ``ArrayArrayCodec``, or dict or string representations of ``ArrayArrayCodec``. If no ``filters`` are provided, a default set of filters will be used. These defaults can be changed by modifying the value of ``array.v3_default_filters`` diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index fe491a4cc8..ea3257e876 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -4053,7 +4053,7 @@ async def create_array( chunk to bytes. For Zarr format 3, a "filter" is a codec that takes an array and returns an array, - and these values must be instances of ``ArrayArrayCodec``, or dict representations + and these values must be instances of ``ArrayArrayCodec``, or dict or string representations of ``ArrayArrayCodec``. If no ``filters`` are provided, a default set of filters will be used. These defaults can be changed by modifying the value of ``array.v3_default_filters`` diff --git a/src/zarr/core/group.py b/src/zarr/core/group.py index 1f5d57c0ab..5d08e841ca 100644 --- a/src/zarr/core/group.py +++ b/src/zarr/core/group.py @@ -1045,7 +1045,7 @@ async def create_array( chunk to bytes. For Zarr format 3, a "filter" is a codec that takes an array and returns an array, - and these values must be instances of ``ArrayArrayCodec``, or dict representations + and these values must be instances of ``ArrayArrayCodec``, or dict or string representations of ``ArrayArrayCodec``. If no ``filters`` are provided, a default set of filters will be used. These defaults can be changed by modifying the value of ``array.v3_default_filters`` @@ -2280,7 +2280,7 @@ def create_array( chunk to bytes. For Zarr format 3, a "filter" is a codec that takes an array and returns an array, - and these values must be instances of ``ArrayArrayCodec``, or dict representations + and these values must be instances of ``ArrayArrayCodec``, or dict or string representations of ``ArrayArrayCodec``. If no ``filters`` are provided, a default set of filters will be used. These defaults can be changed by modifying the value of ``array.v3_default_filters`` @@ -2678,7 +2678,7 @@ def array( chunk to bytes. For Zarr format 3, a "filter" is a codec that takes an array and returns an array, - and these values must be instances of ``ArrayArrayCodec``, or dict representations + and these values must be instances of ``ArrayArrayCodec``, or dict or string representations of ``ArrayArrayCodec``. If no ``filters`` are provided, a default set of filters will be used. These defaults can be changed by modifying the value of ``array.v3_default_filters`` From 0e227e02dec30ac55330890746cd6b63ec81929a Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sat, 15 Feb 2025 23:48:59 +0100 Subject: [PATCH 06/11] document changes --- changes/2839.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/2839.feature.rst diff --git a/changes/2839.feature.rst b/changes/2839.feature.rst new file mode 100644 index 0000000000..5256493563 --- /dev/null +++ b/changes/2839.feature.rst @@ -0,0 +1 @@ +Array creation allows string representation of codecs for ``filters``, ``serializer``, and ``compressors``. \ No newline at end of file From de83f920083a2e85214ad88a7ba0fb63e3c8ee87 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sun, 16 Feb 2025 00:16:55 +0100 Subject: [PATCH 07/11] test_bad_chunk_encoding --- tests/test_array.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_array.py b/tests/test_array.py index 6df8cf581b..cd8320765f 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -1154,6 +1154,30 @@ async def test_v2_chunk_encoding( assert arr.compressors == compressor_expected assert arr.filters == filters_expected + @staticmethod + async def test_bad_chunk_encoding(store: MemoryStore) -> None: + """ + Test that passing an invalid compressor or filter to create_array raises an error. + """ + bad_compressor = 2 + msg = f"For Zarr format 2 arrays, the `compressor` must be a single codec. Expected None, a numcodecs.abc.Codec, or a dict or str representation of a numcodecs.abc.Codec. Got {type(bad_compressor)} instead." + with pytest.raises(ValueError, match=msg): + await create_array( + store=store, + dtype="uint8", + shape=(10,), + zarr_format=2, + compressors=bad_compressor, # type: ignore[arg-type] + ) + with pytest.raises(KeyError): + await create_array( + store=store, + dtype="uint8", + shape=(10,), + zarr_format=3, + filters="bad_filter", + ) + @staticmethod @pytest.mark.parametrize("dtype", ["uint8", "float32", "str"]) async def test_default_filters_compressors( From 73b32ac66f2851e05c43a7d8b75a7f1b8a683a93 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sun, 16 Feb 2025 00:19:32 +0100 Subject: [PATCH 08/11] remove unused "type: ignore" comment --- tests/test_array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_array.py b/tests/test_array.py index cd8320765f..4eed4cacdd 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -1167,7 +1167,7 @@ async def test_bad_chunk_encoding(store: MemoryStore) -> None: dtype="uint8", shape=(10,), zarr_format=2, - compressors=bad_compressor, # type: ignore[arg-type] + compressors=bad_compressor, ) with pytest.raises(KeyError): await create_array( From 3588a65d352f4b5bb946311131571ff2a16c6eb7 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sun, 16 Feb 2025 00:21:01 +0100 Subject: [PATCH 09/11] remove comment --- tests/test_array.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_array.py b/tests/test_array.py index 4eed4cacdd..df61d31661 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -1069,7 +1069,6 @@ async def test_no_filters_compressors(store: MemoryStore, dtype: str, empty_valu ), {"name": "transpose", "configuration": {"order": [0]}}, ({"name": "transpose", "configuration": {"order": [0]}},), - # is there a filter with no configuration? ], ) @pytest.mark.parametrize(("chunks", "shards"), [((6,), None), ((3,), (6,))]) From 74b45bb86059a2da38010b4ee5d57e211e9cd1b4 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Tue, 18 Feb 2025 13:14:53 +0100 Subject: [PATCH 10/11] update test_v3_chunk_encoding --- tests/test_array.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_array.py b/tests/test_array.py index df61d31661..b0d83c1399 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -1102,6 +1102,7 @@ async def test_v3_chunk_encoding( filters=filters, compressors=compressors, serializer=serializer, dtype=np.dtype(dtype) ) assert arr.filters == filters_expected + assert arr.serializer == serializer_expected assert arr.compressors == compressors_expected @staticmethod From 1937ee58ada3225aee8e6af2892574a1871e7907 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Tue, 18 Feb 2025 13:17:35 +0100 Subject: [PATCH 11/11] update test_invalid_chunk_encoding --- tests/test_array.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_array.py b/tests/test_array.py index b0d83c1399..3476964f1d 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -1155,19 +1155,19 @@ async def test_v2_chunk_encoding( assert arr.filters == filters_expected @staticmethod - async def test_bad_chunk_encoding(store: MemoryStore) -> None: + async def test_invalid_chunk_encoding(store: MemoryStore) -> None: """ Test that passing an invalid compressor or filter to create_array raises an error. """ - bad_compressor = 2 - msg = f"For Zarr format 2 arrays, the `compressor` must be a single codec. Expected None, a numcodecs.abc.Codec, or a dict or str representation of a numcodecs.abc.Codec. Got {type(bad_compressor)} instead." + invalid_compressor_type = 2 + msg = f"For Zarr format 2 arrays, the `compressor` must be a single codec. Expected None, a numcodecs.abc.Codec, or a dict or str representation of a numcodecs.abc.Codec. Got {type(invalid_compressor_type)} instead." with pytest.raises(ValueError, match=msg): await create_array( store=store, dtype="uint8", shape=(10,), zarr_format=2, - compressors=bad_compressor, + compressors=invalid_compressor_type, ) with pytest.raises(KeyError): await create_array( @@ -1175,7 +1175,7 @@ async def test_bad_chunk_encoding(store: MemoryStore) -> None: dtype="uint8", shape=(10,), zarr_format=3, - filters="bad_filter", + filters="nonexistent_filter_name", ) @staticmethod