diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 6b573fd033..8f244f4b25 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -15,7 +15,6 @@ Array, AsyncArray, CompressorLike, - _get_default_chunk_encoding_v2, create_array, from_array, get_array_metadata, @@ -33,7 +32,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, @@ -48,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 @@ -871,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, @@ -1009,13 +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 compressor == "auto": - compressor = default_compressor if synchronizer is not None: warnings.warn("synchronizer is not yet implemented", RuntimeWarning, stacklevel=2) @@ -1029,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" @@ -1067,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/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, diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index a44a4b55d1..312dc0bc4d 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, @@ -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. " @@ -861,6 +862,9 @@ async def _create_v2( else: compressor_parsed = compressor + if filters is None: + filters = default_filters + metadata = cls._create_metadata_v2( shape=shape, dtype=dtype, diff --git a/tests/test_api.py b/tests/test_api.py index da61f97847..b4f25a375e 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1412,3 +1412,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]