diff --git a/changes/3325.removal.rst b/changes/3325.removal.rst new file mode 100644 index 0000000000..0e3d34acfb --- /dev/null +++ b/changes/3325.removal.rst @@ -0,0 +1,33 @@ +The deprecated ``zarr.convenience`` sub-module has been removed. +All functions are available in the top-level `zarr` namespace. + +The following deprecated methods have been removed: + +- ``AsyncArray.create`` - use `zarr.api.asynchronous.create_array` instead. +- ``Array.create`` - use `zarr.create_array` instead. + +The ``codecs`` argument on the removed methods corresponds to a combination of the ``compressors`` and ``serializer`` arguments on their replacements, +and the ``chunk_shape`` argument on the removed methods corresponds to the ``chunks`` argument on their replacements. + +The following deprecated properties have been removed: + +- ``AsyncArray.compressor`` - use ``AsyncArray.compressors[0]`` instead for Zarr format 2 arrays. +- ``Array.compressor`` - use ``Array.compressors[0]`` instead for Zarr format 2 arrays. +- ``AsyncGroup.create_dataset`` - use `AsyncGroup.create_array` instead +- ``AsyncGroup.require_dataset`` - use `AsyncGroup.require_array` instead +- ``Group.create_dataset`` - use `Group.create_array` instead +- ``Group.require_dataset`` - use `Group.require_array` instead +- ``Group.array`` - use `Group.create_array` instead + +The following deprecated functions have been removed: + +- ``zarr.api.asynchronous.tree`` - use `AsyncGroup.tree` instead +- ``zarr.api.synchronous.tree`` - use `Group.tree` instead +- ``zarr.tree`` - use `Group.tree` instead + + +Setting ``zarr.storage.default_compressor`` is deprecated, use `zarr.config` to configure ``array.v2_default_compressor`` +e.g. ``zarr.config.set({'codecs.zstd':'numcodecs.Zstd', 'array.v2_default_compressor.numeric': 'zstd'})`` + +The ``zarr_version`` argument has been removed throughout the library. +Use the equivalent ``zarr_format`` argument instead. diff --git a/docs/user-guide/config.rst b/docs/user-guide/config.rst index 0ae8017ca9..30d5918565 100644 --- a/docs/user-guide/config.rst +++ b/docs/user-guide/config.rst @@ -26,7 +26,7 @@ For more information, see the Configuration options include the following: -- Default Zarr format ``default_zarr_version`` +- Default Zarr format ``default_zarr_format`` - Default array order in memory ``array.order`` - Default filters, serializers and compressors, e.g. ``array.v3_default_filters``, ``array.v3_default_serializer``, ``array.v3_default_compressors``, ``array.v2_default_filters`` and ``array.v2_default_compressor`` - Whether empty chunks are written to storage ``array.write_empty_chunks`` diff --git a/docs/user-guide/v3_migration.rst b/docs/user-guide/v3_migration.rst index 2b53e39b83..e102c3fb28 100644 --- a/docs/user-guide/v3_migration.rst +++ b/docs/user-guide/v3_migration.rst @@ -105,7 +105,7 @@ The Array class 2. Defaulting to ``zarr_format=3`` - newly created arrays will use the version 3 of the Zarr specification. To continue using version 2, set ``zarr_format=2`` when creating arrays - or set ``default_zarr_version=2`` in Zarr's :ref:`runtime configuration `. + or set ``default_zarr_format=2`` in Zarr's :ref:`runtime configuration `. The Group class ~~~~~~~~~~~~~~~ @@ -207,7 +207,7 @@ Miscellaneous - The keyword argument ``zarr_version`` available in most creation functions in :mod:`zarr` (e.g. :func:`zarr.create`, :func:`zarr.open`, :func:`zarr.group`, :func:`zarr.array`) has - been deprecated in favor of ``zarr_format``. + been removed in favor of ``zarr_format``. 🚧 Work in Progress 🚧 ---------------------- diff --git a/src/zarr/__init__.py b/src/zarr/__init__.py index 0d58ecf8e8..5bd3fdc658 100644 --- a/src/zarr/__init__.py +++ b/src/zarr/__init__.py @@ -26,7 +26,6 @@ save, save_array, save_group, - tree, zeros, zeros_like, ) @@ -119,7 +118,6 @@ def print_packages(packages: list[str]) -> None: "save", "save_array", "save_group", - "tree", "zeros", "zeros_like", ] diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 78b68caf73..adae2b532d 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -7,7 +7,6 @@ import numpy as np import numpy.typing as npt -from typing_extensions import deprecated from zarr.abc.store import Store from zarr.core.array import ( @@ -42,7 +41,6 @@ from zarr.errors import ( GroupNotFoundError, NodeTypeValidationError, - ZarrDeprecationWarning, ZarrRuntimeWarning, ZarrUserWarning, ) @@ -89,7 +87,6 @@ "save", "save_array", "save_group", - "tree", "zeros", "zeros_like", ] @@ -158,22 +155,6 @@ def _like_args(a: ArrayLike, kwargs: dict[str, Any]) -> dict[str, Any]: return new -def _handle_zarr_version_or_format( - *, zarr_version: ZarrFormat | None, zarr_format: ZarrFormat | None -) -> ZarrFormat | None: - """Handle the deprecated zarr_version kwarg and return zarr_format""" - if zarr_format is not None and zarr_version is not None and zarr_format != zarr_version: - raise ValueError( - f"zarr_format {zarr_format} does not match zarr_version {zarr_version}, please only set one" - ) - if zarr_version is not None: - warnings.warn( - "zarr_version is deprecated, use zarr_format", ZarrDeprecationWarning, stacklevel=2 - ) - return zarr_version - return zarr_format - - async def consolidate_metadata( store: StoreLike, path: str | None = None, @@ -267,7 +248,6 @@ async def load( store: StoreLike, path: str | None = None, zarr_format: ZarrFormat | None = None, - zarr_version: ZarrFormat | None = None, ) -> NDArrayLikeOrScalar | dict[str, NDArrayLikeOrScalar]: """Load data from an array or group into memory. @@ -294,8 +274,6 @@ async def load( If loading data from a group of arrays, data will not be immediately loaded into memory. Rather, arrays will be loaded into memory as they are requested. """ - zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) - obj = await open(store=store, path=path, zarr_format=zarr_format) if isinstance(obj, AsyncArray): return await obj.getitem(slice(None)) @@ -307,7 +285,6 @@ async def open( *, store: StoreLike | None = None, mode: AccessModeLiteral | None = None, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, path: str | None = None, storage_options: dict[str, Any] | None = None, @@ -341,7 +318,6 @@ async def open( z : array or group Return type depends on what exists in the given store. """ - zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) if mode is None: if isinstance(store, (Store, StorePath)) and store.read_only: mode = "r" @@ -390,7 +366,6 @@ async def open_consolidated( async def save( store: StoreLike, *args: NDArrayLike, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, path: str | None = None, **kwargs: Any, # TODO: type kwargs as valid args to save @@ -410,7 +385,6 @@ async def save( **kwargs NumPy arrays with data to save. """ - zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) if len(args) == 0 and len(kwargs) == 0: raise ValueError("at least one array must be provided") @@ -424,7 +398,6 @@ async def save_array( store: StoreLike, arr: NDArrayLike, *, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, path: str | None = None, storage_options: dict[str, Any] | None = None, @@ -449,10 +422,7 @@ async def save_array( **kwargs Passed through to :func:`create`, e.g., compressor. """ - zarr_format = ( - _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) - or _default_zarr_format() - ) + zarr_format = zarr_format or _default_zarr_format() if not isinstance(arr, NDArrayLike): raise TypeError("arr argument must be numpy or other NDArrayLike array") @@ -479,7 +449,6 @@ async def save_array( async def save_group( store: StoreLike, *args: NDArrayLike, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, path: str | None = None, storage_options: dict[str, Any] | None = None, @@ -507,13 +476,7 @@ async def save_group( store_path = await make_store_path(store, path=path, mode="w", storage_options=storage_options) - zarr_format = ( - _handle_zarr_version_or_format( - zarr_version=zarr_version, - zarr_format=zarr_format, - ) - or _default_zarr_format() - ) + zarr_format = zarr_format or _default_zarr_format() for arg in args: if not isinstance(arg, NDArrayLike): @@ -542,31 +505,6 @@ async def save_group( await asyncio.gather(*aws) -@deprecated("Use AsyncGroup.tree instead.", category=ZarrDeprecationWarning) -async def tree(grp: AsyncGroup, expand: bool | None = None, level: int | None = None) -> Any: - """Provide a rich display of the hierarchy. - - .. deprecated:: 3.0.0 - `zarr.tree()` is deprecated and will be removed in a future release. - Use `group.tree()` instead. - - Parameters - ---------- - grp : Group - Zarr or h5py group. - expand : bool, optional - Only relevant for HTML representation. If True, tree will be fully expanded. - level : int, optional - Maximum depth to descend into hierarchy. - - Returns - ------- - TreeRepr - A pretty-printable object displaying the hierarchy. - """ - return await grp.tree(expand=expand, level=level) - - async def array( data: npt.ArrayLike | Array, **kwargs: Any ) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]: @@ -629,7 +567,6 @@ async def group( cache_attrs: bool | None = None, # not used, default changed synchronizer: Any | None = None, # not used path: str | None = None, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, meta_array: Any | None = None, # not used attributes: dict[str, JSON] | None = None, @@ -670,8 +607,6 @@ async def group( The new group. """ - zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) - mode: AccessModeLiteral if overwrite: mode = "w" @@ -762,7 +697,6 @@ async def open_group( path: str | None = None, chunk_store: StoreLike | None = None, # not used storage_options: dict[str, Any] | None = None, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, meta_array: Any | None = None, # not used attributes: dict[str, JSON] | None = None, @@ -830,8 +764,6 @@ async def open_group( The new group. """ - zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) - if cache_attrs is not None: warnings.warn("cache_attrs is not yet implemented", ZarrRuntimeWarning, stacklevel=2) if synchronizer is not None: @@ -884,7 +816,6 @@ async def create( object_codec: Codec | None = None, # TODO: type has changed dimension_separator: Literal[".", "/"] | None = None, write_empty_chunks: bool | None = None, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, meta_array: Any | None = None, # TODO: need type attributes: dict[str, JSON] | None = None, @@ -1011,10 +942,7 @@ async def create( z : array The array. """ - zarr_format = ( - _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) - or _default_zarr_format() - ) + zarr_format = zarr_format or _default_zarr_format() if synchronizer is not None: warnings.warn("synchronizer is not yet implemented", ZarrRuntimeWarning, stacklevel=2) @@ -1217,7 +1145,6 @@ async def ones_like( async def open_array( *, # note: this is a change from v2 store: StoreLike | None = None, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, path: PathLike = "", storage_options: dict[str, Any] | None = None, @@ -1229,8 +1156,6 @@ async def open_array( ---------- store : Store or str Store or path to directory in file system or name of zip file. - zarr_version : {2, 3, None}, optional - The zarr format to use when saving. Deprecated in favor of zarr_format. zarr_format : {2, 3, None}, optional The zarr format to use when saving. path : str, optional @@ -1250,8 +1175,6 @@ async def open_array( mode = kwargs.pop("mode", None) store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options) - zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) - if "write_empty_chunks" in kwargs: _warn_write_empty_chunks_kwarg() diff --git a/src/zarr/api/synchronous.py b/src/zarr/api/synchronous.py index ed1ae2cf2a..243db0d1d7 100644 --- a/src/zarr/api/synchronous.py +++ b/src/zarr/api/synchronous.py @@ -2,15 +2,12 @@ from typing import TYPE_CHECKING, Any, Literal -from typing_extensions import deprecated - import zarr.api.asynchronous as async_api import zarr.core.array from zarr.core.array import DEFAULT_FILL_VALUE, Array, AsyncArray, CompressorLike from zarr.core.group import Group from zarr.core.sync import sync from zarr.core.sync_group import create_hierarchy -from zarr.errors import ZarrDeprecationWarning if TYPE_CHECKING: from collections.abc import Iterable @@ -68,7 +65,6 @@ "save", "save_array", "save_group", - "tree", "zeros", "zeros_like", ] @@ -128,7 +124,6 @@ def load( store: StoreLike, path: str | None = None, zarr_format: ZarrFormat | None = None, - zarr_version: ZarrFormat | None = None, ) -> NDArrayLikeOrScalar | dict[str, NDArrayLikeOrScalar]: """Load data from an array or group into memory. @@ -155,16 +150,13 @@ def load( If loading data from a group of arrays, data will not be immediately loaded into memory. Rather, arrays will be loaded into memory as they are requested. """ - return sync( - async_api.load(store=store, zarr_version=zarr_version, zarr_format=zarr_format, path=path) - ) + return sync(async_api.load(store=store, zarr_format=zarr_format, path=path)) def open( store: StoreLike | None = None, *, mode: AccessModeLiteral | None = None, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, path: str | None = None, storage_options: dict[str, Any] | None = None, @@ -202,7 +194,6 @@ def open( async_api.open( store=store, mode=mode, - zarr_version=zarr_version, zarr_format=zarr_format, path=path, storage_options=storage_options, @@ -227,7 +218,6 @@ def open_consolidated(*args: Any, use_consolidated: Literal[True] = True, **kwar def save( store: StoreLike, *args: NDArrayLike, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, path: str | None = None, **kwargs: Any, # TODO: type kwargs as valid args to async_api.save @@ -247,18 +237,13 @@ def save( **kwargs NumPy arrays with data to save. """ - return sync( - async_api.save( - store, *args, zarr_version=zarr_version, zarr_format=zarr_format, path=path, **kwargs - ) - ) + return sync(async_api.save(store, *args, zarr_format=zarr_format, path=path, **kwargs)) def save_array( store: StoreLike, arr: NDArrayLike, *, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, path: str | None = None, storage_options: dict[str, Any] | None = None, @@ -288,7 +273,6 @@ def save_array( async_api.save_array( store=store, arr=arr, - zarr_version=zarr_version, zarr_format=zarr_format, path=path, storage_options=storage_options, @@ -300,7 +284,6 @@ def save_array( def save_group( store: StoreLike, *args: NDArrayLike, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, path: str | None = None, storage_options: dict[str, Any] | None = None, @@ -331,7 +314,6 @@ def save_group( async_api.save_group( store, *args, - zarr_version=zarr_version, zarr_format=zarr_format, path=path, storage_options=storage_options, @@ -340,31 +322,6 @@ def save_group( ) -@deprecated("Use Group.tree instead.", category=ZarrDeprecationWarning) -def tree(grp: Group, expand: bool | None = None, level: int | None = None) -> Any: - """Provide a rich display of the hierarchy. - - .. deprecated:: 3.0.0 - `zarr.tree()` is deprecated and will be removed in a future release. - Use `group.tree()` instead. - - Parameters - ---------- - grp : Group - Zarr or h5py group. - expand : bool, optional - Only relevant for HTML representation. If True, tree will be fully expanded. - level : int, optional - Maximum depth to descend into hierarchy. - - Returns - ------- - TreeRepr - A pretty-printable object displaying the hierarchy. - """ - return sync(async_api.tree(grp._async_group, expand=expand, level=level)) - - # TODO: add type annotations for kwargs def array(data: npt.ArrayLike | Array, **kwargs: Any) -> Array: """Create an array filled with `data`. @@ -393,7 +350,6 @@ def group( cache_attrs: bool | None = None, # not used, default changed synchronizer: Any | None = None, # not used path: str | None = None, - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, meta_array: Any | None = None, # not used attributes: dict[str, JSON] | None = None, @@ -442,7 +398,6 @@ def group( cache_attrs=cache_attrs, synchronizer=synchronizer, path=path, - zarr_version=zarr_version, zarr_format=zarr_format, meta_array=meta_array, attributes=attributes, @@ -461,7 +416,6 @@ def open_group( path: str | None = None, chunk_store: StoreLike | None = None, # not used in async api storage_options: dict[str, Any] | None = None, # not used in async api - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, meta_array: Any | None = None, # not used in async api attributes: dict[str, JSON] | None = None, @@ -538,7 +492,6 @@ def open_group( path=path, chunk_store=chunk_store, storage_options=storage_options, - zarr_version=zarr_version, zarr_format=zarr_format, meta_array=meta_array, attributes=attributes, @@ -617,7 +570,6 @@ def create( object_codec: Codec | None = None, # TODO: type has changed dimension_separator: Literal[".", "/"] | None = None, write_empty_chunks: bool | None = None, # TODO: default has changed - zarr_version: ZarrFormat | None = None, # deprecated zarr_format: ZarrFormat | None = None, meta_array: Any | None = None, # TODO: need type attributes: dict[str, JSON] | None = None, @@ -732,7 +684,6 @@ def create( object_codec=object_codec, dimension_separator=dimension_separator, write_empty_chunks=write_empty_chunks, - zarr_version=zarr_version, zarr_format=zarr_format, meta_array=meta_array, attributes=attributes, @@ -1264,7 +1215,6 @@ def ones_like(a: ArrayLike, **kwargs: Any) -> Array: def open_array( store: StoreLike | None = None, *, - zarr_version: ZarrFormat | None = None, path: PathLike = "", storage_options: dict[str, Any] | None = None, **kwargs: Any, @@ -1275,8 +1225,6 @@ def open_array( ---------- store : Store or str Store or path to directory in file system or name of zip file. - zarr_version : {2, 3, None}, optional - The zarr format to use when saving. path : str, optional Path in store to array. storage_options : dict @@ -1294,7 +1242,6 @@ def open_array( sync( async_api.open_array( store=store, - zarr_version=zarr_version, path=path, storage_options=storage_options, **kwargs, diff --git a/src/zarr/convenience.py b/src/zarr/convenience.py deleted file mode 100644 index 3ca4ffcb4b..0000000000 --- a/src/zarr/convenience.py +++ /dev/null @@ -1,46 +0,0 @@ -""" -Convenience helpers. - -.. warning:: - - This sub-module is deprecated. All functions here are defined - in the top level zarr namespace instead. -""" - -import warnings - -from zarr.api.synchronous import ( - consolidate_metadata, - copy, - copy_all, - copy_store, - load, - open, - open_consolidated, - save, - save_array, - save_group, - tree, -) -from zarr.errors import ZarrDeprecationWarning - -__all__ = [ - "consolidate_metadata", - "copy", - "copy_all", - "copy_store", - "load", - "open", - "open_consolidated", - "save", - "save_array", - "save_group", - "tree", -] - -warnings.warn( - "zarr.convenience is deprecated. " - "Import these functions from the top level zarr. namespace instead.", - ZarrDeprecationWarning, - stacklevel=2, -) diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index 311a0eb986..c5a7af076e 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -22,7 +22,6 @@ import numcodecs import numcodecs.abc import numpy as np -from typing_extensions import deprecated import zarr from zarr.abc.codec import ArrayArrayCodec, ArrayBytesCodec, BytesBytesCodec, Codec @@ -119,7 +118,7 @@ ) from zarr.core.metadata.v3 import parse_node_type_array from zarr.core.sync import sync -from zarr.errors import MetadataValidationError, ZarrDeprecationWarning, ZarrUserWarning +from zarr.errors import MetadataValidationError, ZarrUserWarning from zarr.registry import ( _parse_array_array_codec, _parse_array_bytes_codec, @@ -325,263 +324,6 @@ def __init__( create_codec_pipeline(metadata=metadata_parsed, store=store_path.store), ) - # this overload defines the function signature when zarr_format is 2 - @overload - @classmethod - async def create( - cls, - store: StoreLike, - *, - # v2 and v3 - shape: ShapeLike, - dtype: ZDTypeLike, - zarr_format: Literal[2], - fill_value: Any | None = DEFAULT_FILL_VALUE, - attributes: dict[str, JSON] | None = None, - chunks: ShapeLike | None = None, - dimension_separator: Literal[".", "/"] | None = None, - order: MemoryOrder | None = None, - filters: list[dict[str, JSON]] | None = None, - compressor: CompressorLikev2 | Literal["auto"] = "auto", - # runtime - overwrite: bool = False, - data: npt.ArrayLike | None = None, - config: ArrayConfigLike | None = None, - ) -> AsyncArray[ArrayV2Metadata]: ... - - # this overload defines the function signature when zarr_format is 3 - @overload - @classmethod - async def create( - cls, - store: StoreLike, - *, - # v2 and v3 - shape: ShapeLike, - dtype: ZDTypeLike, - zarr_format: Literal[3], - fill_value: Any | None = DEFAULT_FILL_VALUE, - attributes: dict[str, JSON] | None = None, - # v3 only - chunk_shape: ShapeLike | None = None, - chunk_key_encoding: ( - ChunkKeyEncoding - | tuple[Literal["default"], Literal[".", "/"]] - | tuple[Literal["v2"], Literal[".", "/"]] - | None - ) = None, - codecs: Iterable[Codec | dict[str, JSON]] | None = None, - dimension_names: DimensionNames = None, - # runtime - overwrite: bool = False, - data: npt.ArrayLike | None = None, - config: ArrayConfigLike | None = None, - ) -> AsyncArray[ArrayV3Metadata]: ... - - @overload - @classmethod - async def create( - cls, - store: StoreLike, - *, - # v2 and v3 - shape: ShapeLike, - dtype: ZDTypeLike, - zarr_format: Literal[3] = 3, - fill_value: Any | None = DEFAULT_FILL_VALUE, - attributes: dict[str, JSON] | None = None, - # v3 only - chunk_shape: ShapeLike | None = None, - chunk_key_encoding: ( - ChunkKeyEncoding - | tuple[Literal["default"], Literal[".", "/"]] - | tuple[Literal["v2"], Literal[".", "/"]] - | None - ) = None, - codecs: Iterable[Codec | dict[str, JSON]] | None = None, - dimension_names: DimensionNames = None, - # runtime - overwrite: bool = False, - data: npt.ArrayLike | None = None, - config: ArrayConfigLike | None = None, - ) -> AsyncArray[ArrayV3Metadata]: ... - - @overload - @classmethod - async def create( - cls, - store: StoreLike, - *, - # v2 and v3 - shape: ShapeLike, - dtype: ZDTypeLike, - zarr_format: ZarrFormat, - fill_value: Any | None = DEFAULT_FILL_VALUE, - attributes: dict[str, JSON] | None = None, - # v3 only - chunk_shape: ShapeLike | None = None, - chunk_key_encoding: ( - ChunkKeyEncoding - | tuple[Literal["default"], Literal[".", "/"]] - | tuple[Literal["v2"], Literal[".", "/"]] - | None - ) = None, - codecs: Iterable[Codec | dict[str, JSON]] | None = None, - dimension_names: DimensionNames = None, - # v2 only - chunks: ShapeLike | None = None, - dimension_separator: Literal[".", "/"] | None = None, - order: MemoryOrder | None = None, - filters: list[dict[str, JSON]] | None = None, - compressor: CompressorLike = "auto", - # runtime - overwrite: bool = False, - data: npt.ArrayLike | None = None, - config: ArrayConfigLike | None = None, - ) -> AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]: ... - - @classmethod - @deprecated("Use zarr.api.asynchronous.create_array instead.", category=ZarrDeprecationWarning) - async def create( - cls, - store: StoreLike, - *, - # v2 and v3 - shape: ShapeLike, - dtype: ZDTypeLike, - zarr_format: ZarrFormat = 3, - fill_value: Any | None = DEFAULT_FILL_VALUE, - attributes: dict[str, JSON] | None = None, - # v3 only - chunk_shape: ShapeLike | None = None, - chunk_key_encoding: ( - ChunkKeyEncodingLike - | tuple[Literal["default"], Literal[".", "/"]] - | tuple[Literal["v2"], Literal[".", "/"]] - | None - ) = None, - codecs: Iterable[Codec | dict[str, JSON]] | None = None, - dimension_names: DimensionNames = None, - # v2 only - chunks: ShapeLike | None = None, - dimension_separator: Literal[".", "/"] | None = None, - order: MemoryOrder | None = None, - filters: list[dict[str, JSON]] | None = None, - compressor: CompressorLike = "auto", - # runtime - overwrite: bool = False, - data: npt.ArrayLike | None = None, - config: ArrayConfigLike | None = None, - ) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]: - """Method to create a new asynchronous array instance. - - .. deprecated:: 3.0.0 - Deprecated in favor of :func:`zarr.api.asynchronous.create_array`. - - Parameters - ---------- - store : StoreLike - The store where the array will be created. - shape : ShapeLike - The shape of the array. - dtype : ZDTypeLike - The data type of the array. - zarr_format : ZarrFormat, optional - The Zarr format version (default is 3). - fill_value : Any, optional - The fill value of the array (default is None). - attributes : dict[str, JSON], optional - The attributes of the array (default is None). - chunk_shape : ChunkCoords, optional - The shape of the array's chunks - Zarr format 3 only. Zarr format 2 arrays should use `chunks` instead. - If not specified, default are guessed based on the shape and dtype. - chunk_key_encoding : ChunkKeyEncodingLike, optional - A specification of how the chunk keys are represented in storage. - Zarr format 3 only. Zarr format 2 arrays should use `dimension_separator` instead. - Default is ``("default", "/")``. - codecs : Sequence of Codecs or dicts, optional - An iterable of Codec or dict serializations of Codecs. The elements of - this collection specify the transformation from array values to stored bytes. - Zarr format 3 only. Zarr format 2 arrays should use ``filters`` and ``compressor`` instead. - - If no codecs are provided, default codecs will be used: - - - For numeric arrays, the default is ``BytesCodec`` and ``ZstdCodec``. - - For Unicode strings, the default is ``VLenUTF8Codec`` and ``ZstdCodec``. - - For bytes or objects, the default is ``VLenBytesCodec`` and ``ZstdCodec``. - - These defaults can be changed by modifying the value of ``array.v3_default_filters``, - ``array.v3_default_serializer`` and ``array.v3_default_compressors`` in :mod:`zarr.core.config`. - dimension_names : Iterable[str | None], optional - The names of the dimensions (default is None). - Zarr format 3 only. Zarr format 2 arrays should not use this parameter. - chunks : ShapeLike, optional - The shape of the array's chunks. - Zarr format 2 only. Zarr format 3 arrays should use ``chunk_shape`` instead. - If not specified, default are guessed based on the shape and dtype. - dimension_separator : Literal[".", "/"], optional - The dimension separator (default is "."). - Zarr format 2 only. Zarr format 3 arrays should use ``chunk_key_encoding`` instead. - order : Literal["C", "F"], optional - The memory of the array (default is "C"). - If ``zarr_format`` is 2, this parameter sets the memory order of the array. - If `zarr_format`` is 3, then this parameter is deprecated, because memory order - is a runtime parameter for Zarr 3 arrays. The recommended way to specify the memory - order for Zarr 3 arrays is via the ``config`` parameter, e.g. ``{'config': 'C'}``. - filters : list[dict[str, JSON]], optional - Sequence of filters to use to encode chunk data prior to compression. - Zarr format 2 only. Zarr format 3 arrays should use ``codecs`` instead. If no ``filters`` - are provided, a default set of filters will be used. - These defaults can be changed by modifying the value of ``array.v2_default_filters`` in :mod:`zarr.core.config`. - compressor : dict[str, JSON], optional - The compressor used to compress the data (default is None). - Zarr format 2 only. Zarr format 3 arrays should use ``codecs`` instead. - - If no ``compressor`` is provided, a default compressor will be used: - - - For numeric arrays, the default is ``ZstdCodec``. - - For Unicode strings, the default is ``VLenUTF8Codec``. - - For bytes or objects, the default is ``VLenBytesCodec``. - - These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`. - overwrite : bool, optional - Whether to raise an error if the store already exists (default is False). - data : npt.ArrayLike, optional - The data to be inserted into the array (default is None). - config : ArrayConfigLike, optional - Runtime configuration for the array. - - Returns - ------- - AsyncArray - The created asynchronous array instance. - """ - return await cls._create( - store, - # v2 and v3 - shape=shape, - dtype=dtype, - zarr_format=zarr_format, - fill_value=fill_value, - attributes=attributes, - # v3 only - chunk_shape=chunk_shape, - chunk_key_encoding=chunk_key_encoding, - codecs=codecs, - dimension_names=dimension_names, - # v2 only - chunks=chunks, - dimension_separator=dimension_separator, - order=order, - filters=filters, - compressor=compressor, - # runtime - overwrite=overwrite, - data=data, - config=config, - ) - @classmethod async def _create( cls, @@ -1060,20 +802,6 @@ def serializer(self) -> ArrayBytesCodec | None: codec for codec in self.metadata.inner_codecs if isinstance(codec, ArrayBytesCodec) ) - @property - @deprecated("Use AsyncArray.compressors instead.", category=ZarrDeprecationWarning) - def compressor(self) -> numcodecs.abc.Codec | None: - """ - Compressor that is applied to each chunk of the array. - - .. deprecated:: 3.0.0 - `array.compressor` is deprecated and will be removed in a future release. - Use `array.compressors` instead. - """ - if self.metadata.zarr_format == 2: - return self.metadata.compressor - raise TypeError("`compressor` is not available for Zarr format 3 arrays.") - @property def compressors(self) -> tuple[numcodecs.abc.Codec, ...] | tuple[BytesBytesCodec, ...]: """ @@ -1854,194 +1582,6 @@ class Array: _async_array: AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata] - @classmethod - @deprecated("Use zarr.create_array instead.", category=ZarrDeprecationWarning) - def create( - cls, - store: StoreLike, - *, - # v2 and v3 - shape: ChunkCoords, - dtype: ZDTypeLike, - zarr_format: ZarrFormat = 3, - fill_value: Any | None = DEFAULT_FILL_VALUE, - attributes: dict[str, JSON] | None = None, - # v3 only - chunk_shape: ChunkCoords | None = None, - chunk_key_encoding: ( - ChunkKeyEncoding - | tuple[Literal["default"], Literal[".", "/"]] - | tuple[Literal["v2"], Literal[".", "/"]] - | None - ) = None, - codecs: Iterable[Codec | dict[str, JSON]] | None = None, - dimension_names: DimensionNames = None, - # v2 only - chunks: ChunkCoords | None = None, - dimension_separator: Literal[".", "/"] | None = None, - order: MemoryOrder | None = None, - filters: list[dict[str, JSON]] | None = None, - compressor: CompressorLike = "auto", - # runtime - overwrite: bool = False, - config: ArrayConfigLike | None = None, - ) -> Array: - """Creates a new Array instance from an initialized store. - - .. deprecated:: 3.0.0 - Deprecated in favor of :func:`zarr.create_array`. - - Parameters - ---------- - store : StoreLike - The array store that has already been initialized. - shape : ChunkCoords - The shape of the array. - dtype : ZDTypeLike - The data type of the array. - chunk_shape : ChunkCoords, optional - The shape of the Array's chunks. - Zarr format 3 only. Zarr format 2 arrays should use `chunks` instead. - If not specified, default are guessed based on the shape and dtype. - chunk_key_encoding : ChunkKeyEncodingLike, optional - A specification of how the chunk keys are represented in storage. - Zarr format 3 only. Zarr format 2 arrays should use `dimension_separator` instead. - Default is ``("default", "/")``. - codecs : Sequence of Codecs or dicts, optional - An iterable of Codec or dict serializations of Codecs. The elements of - this collection specify the transformation from array values to stored bytes. - Zarr format 3 only. Zarr format 2 arrays should use ``filters`` and ``compressor`` instead. - - If no codecs are provided, default codecs will be used: - - - For numeric arrays, the default is ``BytesCodec`` and ``ZstdCodec``. - - For Unicode strings, the default is ``VLenUTF8Codec`` and ``ZstdCodec``. - - For bytes or objects, the default is ``VLenBytesCodec`` and ``ZstdCodec``. - - These defaults can be changed by modifying the value of ``array.v3_default_filters``, - ``array.v3_default_serializer`` and ``array.v3_default_compressors`` in :mod:`zarr.core.config`. - dimension_names : Iterable[str | None], optional - The names of the dimensions (default is None). - Zarr format 3 only. Zarr format 2 arrays should not use this parameter. - chunks : ChunkCoords, optional - The shape of the array's chunks. - Zarr format 2 only. Zarr format 3 arrays should use ``chunk_shape`` instead. - If not specified, default are guessed based on the shape and dtype. - dimension_separator : Literal[".", "/"], optional - The dimension separator (default is "."). - Zarr format 2 only. Zarr format 3 arrays should use ``chunk_key_encoding`` instead. - order : Literal["C", "F"], optional - The memory of the array (default is "C"). - If ``zarr_format`` is 2, this parameter sets the memory order of the array. - If `zarr_format`` is 3, then this parameter is deprecated, because memory order - is a runtime parameter for Zarr 3 arrays. The recommended way to specify the memory - order for Zarr 3 arrays is via the ``config`` parameter, e.g. ``{'order': 'C'}``. - filters : list[dict[str, JSON]], optional - Sequence of filters to use to encode chunk data prior to compression. - Zarr format 2 only. Zarr format 3 arrays should use ``codecs`` instead. If no ``filters`` - are provided, a default set of filters will be used. - These defaults can be changed by modifying the value of ``array.v2_default_filters`` in :mod:`zarr.core.config`. - compressor : dict[str, JSON], optional - Primary compressor to compress chunk data. - Zarr format 2 only. Zarr format 3 arrays should use ``codecs`` instead. - - If no ``compressor`` is provided, a default compressor will be used: - - - For numeric arrays, the default is ``ZstdCodec``. - - For Unicode strings, the default is ``VLenUTF8Codec``. - - For bytes or objects, the default is ``VLenBytesCodec``. - - These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`. - overwrite : bool, optional - Whether to raise an error if the store already exists (default is False). - - Returns - ------- - Array - Array created from the store. - """ - return cls._create( - store, - # v2 and v3 - shape=shape, - dtype=dtype, - zarr_format=zarr_format, - attributes=attributes, - fill_value=fill_value, - # v3 only - chunk_shape=chunk_shape, - chunk_key_encoding=chunk_key_encoding, - codecs=codecs, - dimension_names=dimension_names, - # v2 only - chunks=chunks, - dimension_separator=dimension_separator, - order=order, - filters=filters, - compressor=compressor, - # runtime - overwrite=overwrite, - config=config, - ) - - @classmethod - def _create( - cls, - store: StoreLike, - *, - # v2 and v3 - shape: ChunkCoords, - dtype: ZDTypeLike, - zarr_format: ZarrFormat = 3, - fill_value: Any | None = DEFAULT_FILL_VALUE, - attributes: dict[str, JSON] | None = None, - # v3 only - chunk_shape: ChunkCoords | None = None, - chunk_key_encoding: ( - ChunkKeyEncoding - | tuple[Literal["default"], Literal[".", "/"]] - | tuple[Literal["v2"], Literal[".", "/"]] - | None - ) = None, - codecs: Iterable[Codec | dict[str, JSON]] | None = None, - dimension_names: DimensionNames = None, - # v2 only - chunks: ChunkCoords | None = None, - dimension_separator: Literal[".", "/"] | None = None, - order: MemoryOrder | None = None, - filters: list[dict[str, JSON]] | None = None, - compressor: CompressorLike = "auto", - # runtime - overwrite: bool = False, - config: ArrayConfigLike | None = None, - ) -> Array: - """Creates a new Array instance from an initialized store. - See :func:`Array.create` for more details. - Deprecated in favor of :func:`zarr.create_array`. - """ - async_array = sync( - AsyncArray._create( - store=store, - shape=shape, - dtype=dtype, - zarr_format=zarr_format, - attributes=attributes, - fill_value=fill_value, - chunk_shape=chunk_shape, - chunk_key_encoding=chunk_key_encoding, - codecs=codecs, - dimension_names=dimension_names, - chunks=chunks, - dimension_separator=dimension_separator, - order=order, - filters=filters, - compressor=compressor, - overwrite=overwrite, - config=config, - ), - ) - return cls(async_array) - @classmethod def from_dict( cls, @@ -2241,18 +1781,6 @@ def serializer(self) -> None | ArrayBytesCodec: """ return self._async_array.serializer - @property - @deprecated("Use Array.compressors instead.", category=ZarrDeprecationWarning) - def compressor(self) -> numcodecs.abc.Codec | None: - """ - Compressor that is applied to each chunk of the array. - - .. deprecated:: 3.0.0 - `array.compressor` is deprecated and will be removed in a future release. - Use `array.compressors` instead. - """ - return self._async_array.compressor - @property def compressors(self) -> tuple[numcodecs.abc.Codec, ...] | tuple[BytesBytesCodec, ...]: """ diff --git a/src/zarr/core/common.py b/src/zarr/core/common.py index 4c0247426e..60dcb51a53 100644 --- a/src/zarr/core/common.py +++ b/src/zarr/core/common.py @@ -221,5 +221,5 @@ def _warn_order_kwarg() -> None: def _default_zarr_format() -> ZarrFormat: - """Return the default zarr_version""" + """Return the default zarr format""" return cast("ZarrFormat", int(zarr_config.get("default_zarr_format", 3))) diff --git a/src/zarr/core/group.py b/src/zarr/core/group.py index 4bdc7b549f..2fc0f261cb 100644 --- a/src/zarr/core/group.py +++ b/src/zarr/core/group.py @@ -13,7 +13,6 @@ import numpy as np import numpy.typing as npt -from typing_extensions import deprecated import zarr.api.asynchronous as async_api from zarr.abc.metadata import Metadata @@ -55,7 +54,6 @@ ContainsArrayError, ContainsGroupError, MetadataValidationError, - ZarrDeprecationWarning, ZarrUserWarning, ) from zarr.storage import StoreLike, StorePath @@ -74,7 +72,7 @@ ) from typing import Any - from zarr.core.array_spec import ArrayConfig, ArrayConfigLike + from zarr.core.array_spec import ArrayConfigLike from zarr.core.buffer import Buffer, BufferPrototype from zarr.core.chunk_key_encodings import ChunkKeyEncodingLike from zarr.core.common import MemoryOrder @@ -1158,78 +1156,6 @@ async def create_array( write_data=write_data, ) - @deprecated("Use AsyncGroup.create_array instead.", category=ZarrDeprecationWarning) - async def create_dataset( - self, name: str, *, shape: ShapeLike, **kwargs: Any - ) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]: - """Create an array. - - .. deprecated:: 3.0.0 - The h5py compatibility methods will be removed in 3.1.0. Use `AsyncGroup.create_array` instead. - - Arrays are known as "datasets" in HDF5 terminology. For compatibility - with h5py, Zarr groups also implement the :func:`zarr.AsyncGroup.require_dataset` method. - - Parameters - ---------- - name : str - Array name. - **kwargs : dict - Additional arguments passed to :func:`zarr.AsyncGroup.create_array`. - - Returns - ------- - a : AsyncArray - """ - data = kwargs.pop("data", None) - # create_dataset in zarr 2.x requires shape but not dtype if data is - # provided. Allow this configuration by inferring dtype from data if - # necessary and passing it to create_array - if "dtype" not in kwargs and data is not None: - kwargs["dtype"] = data.dtype - array = await self.create_array(name, shape=shape, **kwargs) - if data is not None: - await array.setitem(slice(None), data) - return array - - @deprecated("Use AsyncGroup.require_array instead.", category=ZarrDeprecationWarning) - async def require_dataset( - self, - name: str, - *, - shape: ChunkCoords, - dtype: npt.DTypeLike = None, - exact: bool = False, - **kwargs: Any, - ) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]: - """Obtain an array, creating if it doesn't exist. - - .. deprecated:: 3.0.0 - The h5py compatibility methods will be removed in 3.1.0. Use `AsyncGroup.require_dataset` instead. - - Arrays are known as "datasets" in HDF5 terminology. For compatibility - with h5py, Zarr groups also implement the :func:`zarr.AsyncGroup.create_dataset` method. - - Other `kwargs` are as per :func:`zarr.AsyncGroup.create_dataset`. - - Parameters - ---------- - name : str - Array name. - shape : int or tuple of ints - Array shape. - dtype : str or dtype, optional - NumPy dtype. - exact : bool, optional - If True, require `dtype` to match exactly. If false, require - `dtype` can be cast from array dtype. - - Returns - ------- - a : AsyncArray - """ - return await self.require_array(name, shape=shape, dtype=dtype, exact=exact, **kwargs) - async def require_array( self, name: str, @@ -2593,55 +2519,6 @@ def create_array( ) ) - @deprecated("Use Group.create_array instead.", category=ZarrDeprecationWarning) - def create_dataset(self, name: str, **kwargs: Any) -> Array: - """Create an array. - - .. deprecated:: 3.0.0 - The h5py compatibility methods will be removed in 3.1.0. Use `Group.create_array` instead. - - - Arrays are known as "datasets" in HDF5 terminology. For compatibility - with h5py, Zarr groups also implement the :func:`zarr.Group.require_dataset` method. - - Parameters - ---------- - name : str - Array name. - **kwargs : dict - Additional arguments passed to :func:`zarr.Group.create_array` - - Returns - ------- - a : Array - """ - return Array(self._sync(self._async_group.create_dataset(name, **kwargs))) - - @deprecated("Use Group.require_array instead.", category=ZarrDeprecationWarning) - def require_dataset(self, name: str, *, shape: ShapeLike, **kwargs: Any) -> Array: - """Obtain an array, creating if it doesn't exist. - - .. deprecated:: 3.0.0 - The h5py compatibility methods will be removed in 3.1.0. Use `Group.require_array` instead. - - Arrays are known as "datasets" in HDF5 terminology. For compatibility - with h5py, Zarr groups also implement the :func:`zarr.Group.create_dataset` method. - - Other `kwargs` are as per :func:`zarr.Group.create_dataset`. - - Parameters - ---------- - name : str - Array name. - **kwargs : - See :func:`zarr.Group.create_dataset`. - - Returns - ------- - a : Array - """ - return Array(self._sync(self._async_group.require_array(name, shape=shape, **kwargs))) - def require_array(self, name: str, *, shape: ShapeLike, **kwargs: Any) -> Array: """Obtain an array, creating if it doesn't exist. @@ -2839,150 +2716,6 @@ def move(self, source: str, dest: str) -> None: """ return self._sync(self._async_group.move(source, dest)) - @deprecated("Use Group.create_array instead.", category=ZarrDeprecationWarning) - def array( - self, - name: str, - *, - shape: ShapeLike, - dtype: npt.DTypeLike, - chunks: ChunkCoords | Literal["auto"] = "auto", - shards: ChunkCoords | Literal["auto"] | None = None, - filters: FiltersLike = "auto", - compressors: CompressorsLike = "auto", - compressor: CompressorLike = None, - serializer: SerializerLike = "auto", - fill_value: Any | None = DEFAULT_FILL_VALUE, - order: MemoryOrder | None = None, - attributes: dict[str, JSON] | None = None, - chunk_key_encoding: ChunkKeyEncodingLike | None = None, - dimension_names: DimensionNames = None, - storage_options: dict[str, Any] | None = None, - overwrite: bool = False, - config: ArrayConfig | ArrayConfigLike | None = None, - data: npt.ArrayLike | None = None, - ) -> Array: - """Create an array within this group. - - .. deprecated:: 3.0.0 - Use `Group.create_array` instead. - - This method lightly wraps :func:`zarr.core.array.create_array`. - - Parameters - ---------- - name : str - The name of the array relative to the group. If ``path`` is ``None``, the array will be located - at the root of the store. - shape : ChunkCoords - Shape of the array. - dtype : npt.DTypeLike - Data type of the array. - chunks : ChunkCoords, optional - Chunk shape of the array. - If not specified, default are guessed based on the shape and dtype. - shards : ChunkCoords, optional - Shard shape of the array. The default value of ``None`` results in no sharding at all. - filters : Iterable[Codec], optional - Iterable of filters to apply to each chunk of the array, in order, before serializing that - 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 - 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`` - in :mod:`zarr.core.config`. - Use ``None`` to omit default filters. - - For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the - the order if your filters is consistent with the behavior of each filter. - If no ``filters`` are provided, a default set of filters will be used. - These defaults can be changed by modifying the value of ``array.v2_default_filters`` - in :mod:`zarr.core.config`. - Use ``None`` to omit default filters. - compressors : Iterable[Codec], optional - List of compressors to apply to the array. Compressors are applied in order, and after any - filters are applied (if any are specified) and the data is serialized into bytes. - - For Zarr format 3, a "compressor" is a codec that takes a bytestream, and - returns another bytestream. Multiple compressors my be provided for Zarr format 3. - If no ``compressors`` are provided, a default set of compressors will be used. - These defaults can be changed by modifying the value of ``array.v3_default_compressors`` - in :mod:`zarr.core.config`. - Use ``None`` to omit default compressors. - - For Zarr format 2, a "compressor" can be any numcodecs codec. Only a single compressor may - be provided for Zarr format 2. - If no ``compressor`` is provided, a default compressor will be used. - in :mod:`zarr.core.config`. - Use ``None`` to omit the default compressor. - compressor : Codec, optional - Deprecated in favor of ``compressors``. - serializer : dict[str, JSON] | ArrayBytesCodec, optional - Array-to-bytes codec to use for encoding the array data. - Zarr format 3 only. Zarr format 2 arrays use implicit array-to-bytes conversion. - If no ``serializer`` is provided, a default serializer will be used. - These defaults can be changed by modifying the value of ``array.v3_default_serializer`` - in :mod:`zarr.core.config`. - fill_value : Any, optional - Fill value for the array. - order : {"C", "F"}, optional - The memory of the array (default is "C"). - For Zarr format 2, this parameter sets the memory order of the array. - For Zarr format 3, this parameter is deprecated, because memory order - is a runtime parameter for Zarr format 3 arrays. The recommended way to specify the memory - order for Zarr format 3 arrays is via the ``config`` parameter, e.g. ``{'config': 'C'}``. - If no ``order`` is provided, a default order will be used. - This default can be changed by modifying the value of ``array.order`` in :mod:`zarr.core.config`. - attributes : dict, optional - Attributes for the array. - chunk_key_encoding : ChunkKeyEncoding, optional - A specification of how the chunk keys are represented in storage. - For Zarr format 3, the default is ``{"name": "default", "separator": "/"}}``. - For Zarr format 2, the default is ``{"name": "v2", "separator": "."}}``. - dimension_names : Iterable[str], optional - The names of the dimensions (default is None). - Zarr format 3 only. Zarr format 2 arrays should not use this parameter. - storage_options : dict, optional - If using an fsspec URL to create the store, these will be passed to the backend implementation. - Ignored otherwise. - overwrite : bool, default False - Whether to overwrite an array with the same name in the store, if one exists. - config : ArrayConfig or ArrayConfigLike, optional - Runtime configuration for the array. - data : array_like - The data to fill the array with. - - Returns - ------- - AsyncArray - """ - compressors = _parse_deprecated_compressor(compressor, compressors) - return Array( - self._sync( - self._async_group.create_dataset( - name=name, - shape=shape, - dtype=dtype, - chunks=chunks, - shards=shards, - fill_value=fill_value, - attributes=attributes, - chunk_key_encoding=chunk_key_encoding, - compressors=compressors, - serializer=serializer, - dimension_names=dimension_names, - order=order, - filters=filters, - overwrite=overwrite, - storage_options=storage_options, - config=config, - data=data, - ) - ) - ) - async def create_hierarchy( *, diff --git a/src/zarr/creation.py b/src/zarr/creation.py deleted file mode 100644 index 622406ed75..0000000000 --- a/src/zarr/creation.py +++ /dev/null @@ -1,48 +0,0 @@ -""" -Helpers for creating arrays. - -.. warning:: - - This sub-module is deprecated. All functions here are defined - in the top level zarr namespace instead. -""" - -import warnings - -from zarr.api.synchronous import ( - array, - create, - empty, - empty_like, - full, - full_like, - ones, - ones_like, - open_array, - open_like, - zeros, - zeros_like, -) -from zarr.errors import ZarrDeprecationWarning - -__all__ = [ - "array", - "create", - "empty", - "empty_like", - "full", - "full_like", - "ones", - "ones_like", - "open_array", - "open_like", - "zeros", - "zeros_like", -] - -warnings.warn( - "zarr.creation is deprecated. " - "Import these functions from the top level zarr. namespace instead.", - ZarrDeprecationWarning, - stacklevel=2, -) diff --git a/src/zarr/storage/__init__.py b/src/zarr/storage/__init__.py index 00df50214f..bafe711f1c 100644 --- a/src/zarr/storage/__init__.py +++ b/src/zarr/storage/__init__.py @@ -1,9 +1,3 @@ -import sys -import warnings -from types import ModuleType -from typing import Any - -from zarr.errors import ZarrDeprecationWarning from zarr.storage._common import StoreLike, StorePath from zarr.storage._fsspec import FsspecStore from zarr.storage._local import LocalStore @@ -25,20 +19,3 @@ "WrapperStore", "ZipStore", ] - - -class VerboseModule(ModuleType): - def __setattr__(self, attr: str, value: Any) -> None: - if attr == "default_compressor": - warnings.warn( - "setting zarr.storage.default_compressor is deprecated, use " - "zarr.config to configure array.v2_default_compressor " - "e.g. config.set({'codecs.zstd':'numcodecs.Zstd', 'array.v2_default_compressor.numeric': 'zstd'})", - ZarrDeprecationWarning, - stacklevel=1, - ) - else: - super().__setattr__(attr, value) - - -sys.modules[__name__].__class__ = VerboseModule diff --git a/tests/test_api.py b/tests/test_api.py index 12acf80589..9080e2cc2d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -42,7 +42,7 @@ save_group, ) from zarr.core.buffer import NDArrayLike -from zarr.errors import MetadataValidationError, ZarrDeprecationWarning, ZarrUserWarning +from zarr.errors import MetadataValidationError, ZarrUserWarning from zarr.storage import MemoryStore from zarr.storage._utils import normalize_path from zarr.testing.utils import gpu_test @@ -471,9 +471,6 @@ def test_tree() -> None: g3.create_group("baz") g5 = g3.create_group("qux") g5.create_array("baz", shape=(100,), chunks=(10,), dtype="float64") - with pytest.warns(ZarrDeprecationWarning, match=r"Group\.tree instead\."): # noqa: PT031 - assert repr(zarr.tree(g1)) == repr(g1.tree()) - assert str(zarr.tree(g1)) == str(g1.tree()) # @pytest.mark.parametrize("stores_from_path", [False, True]) diff --git a/tests/test_group.py b/tests/test_group.py index e5cfe82daa..ebe4e48d5d 100644 --- a/tests/test_group.py +++ b/tests/test_group.py @@ -44,7 +44,6 @@ ContainsArrayError, ContainsGroupError, MetadataValidationError, - ZarrDeprecationWarning, ZarrUserWarning, ) from zarr.storage import LocalStore, MemoryStore, StorePath, ZipStore @@ -709,13 +708,11 @@ async def test_group_update_attributes_async(store: Store, zarr_format: ZarrForm assert new_group.attrs == new_attrs -@pytest.mark.parametrize("method", ["create_array", "array"]) @pytest.mark.parametrize("name", ["a", "/a"]) def test_group_create_array( store: Store, zarr_format: ZarrFormat, overwrite: bool, - method: Literal["create_array", "array"], name: str, ) -> None: """ @@ -726,34 +723,12 @@ def test_group_create_array( dtype = "uint8" data = np.arange(np.prod(shape)).reshape(shape).astype(dtype) - if method == "create_array": - array = group.create_array(name=name, shape=shape, dtype=dtype) - array[:] = data - elif method == "array": - with pytest.warns(ZarrDeprecationWarning, match=r"Group\.create_array instead\."): - with pytest.warns( - ZarrUserWarning, - match="The `compressor` argument is deprecated. Use `compressors` instead.", - ): - array = group.array(name=name, data=data, shape=shape, dtype=dtype) - else: - raise AssertionError - + array = group.create_array(name=name, shape=shape, dtype=dtype) + array[:] = data if not overwrite: - if method == "create_array": - with pytest.raises(ContainsArrayError): # noqa: PT012 - a = group.create_array(name=name, shape=shape, dtype=dtype) - a[:] = data - elif method == "array": - with pytest.raises(ContainsArrayError): # noqa: PT012 - with pytest.warns(ZarrDeprecationWarning, match=r"Group\.create_array instead\."): - with pytest.warns( - ZarrUserWarning, - match="The `compressor` argument is deprecated. Use `compressors` instead.", - ): - a = group.array(name=name, shape=shape, dtype=dtype) - a[:] = data - + with pytest.raises(ContainsArrayError): # noqa: PT012 + a = group.create_array(name=name, shape=shape, dtype=dtype) + a[:] = data assert array.path == normalize_path(name) assert array.name == "/" + array.path assert array.shape == shape @@ -1289,38 +1264,6 @@ async def test_require_groups(store: LocalStore | MemoryStore, zarr_format: Zarr assert no_group == () -def test_create_dataset_with_data(store: Store, zarr_format: ZarrFormat) -> None: - """Check that deprecated create_dataset method allows input data. - - See https://github.com/zarr-developers/zarr-python/issues/2631. - """ - root = Group.from_store(store=store, zarr_format=zarr_format) - arr = np.random.random((5, 5)) - with pytest.warns(ZarrDeprecationWarning, match=r"Group\.create_array instead\."): - data = root.create_dataset("random", data=arr, shape=arr.shape) - np.testing.assert_array_equal(np.asarray(data), arr) - - -async def test_create_dataset(store: Store, zarr_format: ZarrFormat) -> None: - root = await AsyncGroup.from_store(store=store, zarr_format=zarr_format) - with pytest.warns(ZarrDeprecationWarning, match=r"Group\.create_array instead\."): - foo = await root.create_dataset("foo", shape=(10,), dtype="uint8") - assert foo.shape == (10,) - - with ( - pytest.raises(ContainsArrayError), - pytest.warns(ZarrDeprecationWarning, match=r"Group\.create_array instead\."), - ): - await root.create_dataset("foo", shape=(100,), dtype="int8") - - _ = await root.create_group("bar") - with ( - pytest.raises(ContainsGroupError), - pytest.warns(ZarrDeprecationWarning, match=r"Group\.create_array instead\."), - ): - await root.create_dataset("bar", shape=(100,), dtype="int8") - - async def test_require_array(store: Store, zarr_format: ZarrFormat) -> None: root = await AsyncGroup.from_store(store=store, zarr_format=zarr_format) foo1 = await root.require_array("foo", shape=(10,), dtype="i8", attributes={"foo": 101}) diff --git a/tests/test_v2.py b/tests/test_v2.py index 70e8f2923f..82a571bbc2 100644 --- a/tests/test_v2.py +++ b/tests/test_v2.py @@ -21,7 +21,6 @@ from zarr.core.dtype.wrapper import ZDType from zarr.core.group import Group from zarr.core.sync import sync -from zarr.errors import ZarrDeprecationWarning from zarr.storage import MemoryStore, StorePath @@ -145,13 +144,15 @@ def test_create_array_defaults(store: Store) -> None: g = zarr.open(store, mode="w", zarr_format=2) assert isinstance(g, Group) arr = g.create_array("one", dtype="i8", shape=(1,), chunks=(1,), compressor=None) - assert arr._async_array.compressor is None + assert arr._async_array.compressors == () assert not (arr.filters) arr = g.create_array("two", dtype="i8", shape=(1,), chunks=(1,)) - assert arr._async_array.compressor is not None + assert arr._async_array.compressors == ( + numcodecs.Blosc(cname="lz4", clevel=5, shuffle=numcodecs.blosc.SHUFFLE, blocksize=0), + ) assert not (arr.filters) arr = g.create_array("three", dtype="i8", shape=(1,), chunks=(1,), compressor=Zstd()) - assert arr._async_array.compressor is not None + assert arr._async_array.compressors == (numcodecs.Zstd(level=0),) assert not (arr.filters) with pytest.raises(ValueError): g.create_array( @@ -226,11 +227,6 @@ def test_v2_non_contiguous(numpy_order: Literal["C", "F"], zarr_order: Literal[" assert (sub_arr).flags.c_contiguous -def test_default_compressor_deprecation_warning() -> None: - with pytest.warns(ZarrDeprecationWarning, match="default_compressor is deprecated"): - zarr.storage.default_compressor = "zarr.codecs.zstd.ZstdCodec()" # type: ignore[attr-defined] - - @pytest.mark.parametrize("fill_value", [None, (b"", 0, 0.0)], ids=["no_fill", "fill"]) def test_structured_dtype_roundtrip(fill_value: float | bytes, tmp_path: Path) -> None: a = np.array(