From 55da505da4b4e08bc9e402ef4ef61cf54071ef93 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 30 May 2025 22:18:17 +0100 Subject: [PATCH 1/6] Remove duplicate compressor handling --- src/zarr/api/asynchronous.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 3b53095636..2b5edaaa58 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -1013,8 +1013,6 @@ async def create( default_filters, default_compressor = _get_default_chunk_encoding_v2(zdtype) if not filters: filters = default_filters # type: ignore[assignment] - if compressor == "auto": - compressor = default_compressor if synchronizer is not None: warnings.warn("synchronizer is not yet implemented", RuntimeWarning, stacklevel=2) From 55f50a25429b10c9659fb877364b1954bb2ad8e3 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 30 May 2025 22:24:13 +0100 Subject: [PATCH 2/6] Push filter parsing down the stack --- src/zarr/api/asynchronous.py | 11 ++++------- src/zarr/core/array.py | 5 ++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 2b5edaaa58..894e8d6988 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -47,6 +47,8 @@ if TYPE_CHECKING: from collections.abc import Iterable + import numcodecs.abc + from zarr.abc.codec import Codec from zarr.core.buffer import NDArrayLikeOrScalar from zarr.core.chunk_key_encodings import ChunkKeyEncoding @@ -870,7 +872,7 @@ async def create( overwrite: bool = False, path: PathLike | None = None, chunk_store: StoreLike | None = None, - filters: list[dict[str, JSON]] | None = None, # TODO: type has changed + filters: Iterable[dict[str, JSON] | numcodecs.abc.Codec] | None = None, cache_metadata: bool | None = None, cache_attrs: bool | None = None, read_only: bool | None = None, @@ -1008,11 +1010,6 @@ async def create( _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) or _default_zarr_format() ) - zdtype = parse_data_type(dtype, zarr_format=zarr_format) - if zarr_format == 2: - default_filters, default_compressor = _get_default_chunk_encoding_v2(zdtype) - if not filters: - filters = default_filters # type: ignore[assignment] if synchronizer is not None: warnings.warn("synchronizer is not yet implemented", RuntimeWarning, stacklevel=2) @@ -1064,7 +1061,7 @@ async def create( store_path, shape=shape, chunks=chunks, - dtype=zdtype, + dtype=dtype, compressor=compressor, fill_value=fill_value, overwrite=overwrite, diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index a44a4b55d1..f039083069 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -591,7 +591,7 @@ async def _create( chunks: ShapeLike | None = None, dimension_separator: Literal[".", "/"] | None = None, order: MemoryOrder | None = None, - filters: list[dict[str, JSON]] | None = None, + filters: Iterable[dict[str, JSON] | numcodecs.abc.Codec] | None = None, compressor: CompressorLike = "auto", # runtime overwrite: bool = False, @@ -861,6 +861,9 @@ async def _create_v2( else: compressor_parsed = compressor + if filters is None: + filters = _default_filters(dtype) + metadata = cls._create_metadata_v2( shape=shape, dtype=dtype, From c78013ddc9af965c62402d839e428b780c4e1686 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 30 May 2025 22:26:05 +0100 Subject: [PATCH 3/6] Put not implemented warnings together --- src/zarr/api/asynchronous.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 894e8d6988..d67b0aa953 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -1023,14 +1023,14 @@ async def create( warnings.warn("object_codec is not yet implemented", RuntimeWarning, stacklevel=2) if read_only is not None: warnings.warn("read_only is not yet implemented", RuntimeWarning, stacklevel=2) + if meta_array is not None: + warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2) + if order is not None: _warn_order_kwarg() if write_empty_chunks is not None: _warn_write_empty_chunks_kwarg() - if meta_array is not None: - warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2) - mode = kwargs.pop("mode", None) if mode is None: mode = "a" From 11d59b54747f70d46b72419cc51a2e4aabba239a Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 7 Jun 2025 14:00:50 +0200 Subject: [PATCH 4/6] Test unimplemented kwargs warn --- tests/test_api.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_api.py b/tests/test_api.py index e6cb612a82..75a68ac7dd 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1372,3 +1372,10 @@ def test_auto_chunks(f: Callable[..., Array]) -> None: a = f(**kwargs) assert a.chunks == (500, 500) + + +@pytest.mark.parametrize("kwarg_name", ["synchronizer", "chunk_store", "cache_attrs", "meta_array"]) +def test_unimplemented_kwarg_warnings(kwarg_name: str) -> None: + kwargs = {kwarg_name: 1} + with pytest.warns(RuntimeWarning, match=".* is not yet implemented"): + zarr.create(shape=(1,), **kwargs) # type: ignore[arg-type] From 1f0c65c253cc4f7c59c0bd241c74744e17bd45e6 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 17 Jun 2025 09:17:40 +0100 Subject: [PATCH 5/6] pre-commit fixes --- src/zarr/api/asynchronous.py | 3 +-- src/zarr/core/array.py | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index d67b0aa953..6956b462e9 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -14,7 +14,6 @@ Array, AsyncArray, CompressorLike, - _get_default_chunk_encoding_v2, create_array, from_array, get_array_metadata, @@ -32,7 +31,7 @@ _warn_order_kwarg, _warn_write_empty_chunks_kwarg, ) -from zarr.core.dtype import ZDTypeLike, get_data_type_from_native_dtype, parse_data_type +from zarr.core.dtype import ZDTypeLike, get_data_type_from_native_dtype from zarr.core.group import ( AsyncGroup, ConsolidatedMetadata, diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index f039083069..312dc0bc4d 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -850,9 +850,10 @@ async def _create_v2( else: await ensure_no_existing_node(store_path, zarr_format=2) + default_filters, default_compressor = _get_default_chunk_encoding_v2(dtype) compressor_parsed: CompressorLikev2 if compressor == "auto": - _, compressor_parsed = _get_default_chunk_encoding_v2(dtype) + compressor_parsed = default_compressor elif isinstance(compressor, BytesBytesCodec): raise ValueError( "Cannot use a BytesBytesCodec as a compressor for zarr v2 arrays. " @@ -862,7 +863,7 @@ async def _create_v2( compressor_parsed = compressor if filters is None: - filters = _default_filters(dtype) + filters = default_filters metadata = cls._create_metadata_v2( shape=shape, From 1df675ad9a78d6a1c08b79c3208eca87070fc15e Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 9 Jul 2025 17:19:31 +0100 Subject: [PATCH 6/6] Fix syncrhonous create() signature --- src/zarr/api/synchronous.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/zarr/api/synchronous.py b/src/zarr/api/synchronous.py index b60f69a673..92b80b1ac8 100644 --- a/src/zarr/api/synchronous.py +++ b/src/zarr/api/synchronous.py @@ -15,6 +15,7 @@ if TYPE_CHECKING: from collections.abc import Iterable + import numcodecs.abc import numpy as np import numpy.typing as npt @@ -613,7 +614,7 @@ def create( overwrite: bool = False, path: PathLike | None = None, chunk_store: StoreLike | None = None, - filters: list[dict[str, JSON]] | None = None, # TODO: type has changed + filters: Iterable[dict[str, JSON] | numcodecs.abc.Codec] | None = None, cache_metadata: bool | None = None, cache_attrs: bool | None = None, read_only: bool | None = None,