Skip to content

Cleanups to implementation of create() #3111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
Array,
AsyncArray,
CompressorLike,
_get_default_chunk_encoding_v2,
create_array,
from_array,
get_array_metadata,
Expand All @@ -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,
Expand All @@ -47,6 +46,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
Expand Down Expand Up @@ -870,7 +871,7 @@
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,
Expand Down Expand Up @@ -1008,13 +1009,6 @@
_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)
Expand All @@ -1028,14 +1022,14 @@
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)

Check warning on line 1026 in src/zarr/api/asynchronous.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/api/asynchronous.py#L1026

Added line #L1026 was not covered by tests

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"
Expand Down Expand Up @@ -1066,7 +1060,7 @@
store_path,
shape=shape,
chunks=chunks,
dtype=zdtype,
dtype=dtype,
compressor=compressor,
fill_value=fill_value,
overwrite=overwrite,
Expand Down
8 changes: 6 additions & 2 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
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,
Expand Down Expand Up @@ -820,9 +820,10 @@
else:
await ensure_no_existing_node(store_path, zarr_format=2)

default_filters, default_compressor = _get_default_chunk_encoding_v2(dtype)

Check warning on line 823 in src/zarr/core/array.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/array.py#L823

Added line #L823 was not covered by tests
compressor_parsed: CompressorLikev2
if compressor == "auto":
_, compressor_parsed = _get_default_chunk_encoding_v2(dtype)
compressor_parsed = default_compressor

Check warning on line 826 in src/zarr/core/array.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/array.py#L826

Added line #L826 was not covered by tests
elif isinstance(compressor, BytesBytesCodec):
raise ValueError(
"Cannot use a BytesBytesCodec as a compressor for zarr v2 arrays. "
Expand All @@ -831,6 +832,9 @@
else:
compressor_parsed = compressor

if filters is None:
filters = default_filters

Check warning on line 836 in src/zarr/core/array.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/array.py#L835-L836

Added lines #L835 - L836 were not covered by tests

metadata = cls._create_metadata_v2(
shape=shape,
dtype=dtype,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]