Skip to content

Commit dd5a321

Browse files
authored
chore: remove deprecated group methods (#3902)
* chore: remove group.array * chore: *_dataset methods from group * docs: changelog
1 parent ab88363 commit dd5a321

File tree

5 files changed

+11
-338
lines changed

5 files changed

+11
-338
lines changed

changes/3902.misc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove deprecated `Group` methods `array`, `require_dataset`, and `create_dataset`.

docs/user-guide/v3_migration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ The following sections provide details on breaking changes in Zarr-Python 3.
107107

108108
1. Disallow direct construction - use [`zarr.open_group`][] or [`zarr.create_group`][]
109109
instead of directly constructing the `zarr.Group` class.
110-
2. Most of the h5py compatibility methods are deprecated and will issue warnings if used.
111-
The following functions are drop in replacements that have the same signature and functionality:
110+
2. The h5py compatibility methods `create_dataset` and `require_dataset` have been removed.
111+
Use the following replacements:
112112

113-
- Use [`zarr.Group.create_array`][] in place of `zarr.Group.create_dataset`
114-
- Use [`zarr.Group.require_array`][] in place of `zarr.Group.require_dataset`
113+
- [`zarr.Group.create_array`][] in place of `Group.create_dataset`
114+
- [`zarr.Group.require_array`][] in place of `Group.require_dataset`
115115
3. Disallow "." syntax for getting group members. To get a member of a group named `foo`,
116116
use `group["foo"]` in place of `group.foo`.
117117
4. The `zarr.storage.init_group` low-level helper function has been removed. Use

src/zarr/core/group.py

Lines changed: 1 addition & 272 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import numpy as np
1515
import numpy.typing as npt
16-
from typing_extensions import deprecated
1716

1817
import zarr.api.asynchronous as async_api
1918
from zarr.abc.metadata import Metadata
@@ -56,7 +55,6 @@
5655
ContainsGroupError,
5756
GroupNotFoundError,
5857
MetadataValidationError,
59-
ZarrDeprecationWarning,
6058
ZarrUserWarning,
6159
)
6260
from zarr.storage import StoreLike, StorePath
@@ -1161,78 +1159,6 @@ async def create_array(
11611159
write_data=write_data,
11621160
)
11631161

1164-
@deprecated("Use AsyncGroup.create_array instead.", category=ZarrDeprecationWarning)
1165-
async def create_dataset(self, name: str, *, shape: ShapeLike, **kwargs: Any) -> AnyAsyncArray:
1166-
"""Create an array.
1167-
1168-
!!! warning "Deprecated"
1169-
`AsyncGroup.create_dataset()` is deprecated since v3.0.0 and will be removed in v3.1.0.
1170-
Use `AsyncGroup.create_array` instead.
1171-
1172-
Arrays are known as "datasets" in HDF5 terminology. For compatibility
1173-
with h5py, Zarr groups also implement the [zarr.AsyncGroup.require_dataset][] method.
1174-
1175-
Parameters
1176-
----------
1177-
name : str
1178-
Array name.
1179-
**kwargs : dict
1180-
Additional arguments passed to [zarr.AsyncGroup.create_array][].
1181-
1182-
Returns
1183-
-------
1184-
a : AsyncArray
1185-
"""
1186-
data = kwargs.pop("data", None)
1187-
# create_dataset in zarr 2.x requires shape but not dtype if data is
1188-
# provided. Allow this configuration by inferring dtype from data if
1189-
# necessary and passing it to create_array
1190-
if "dtype" not in kwargs and data is not None:
1191-
kwargs["dtype"] = data.dtype
1192-
array = await self.create_array(name, shape=shape, **kwargs)
1193-
if data is not None:
1194-
await array.setitem(slice(None), data)
1195-
return array
1196-
1197-
@deprecated("Use AsyncGroup.require_array instead.", category=ZarrDeprecationWarning)
1198-
async def require_dataset(
1199-
self,
1200-
name: str,
1201-
*,
1202-
shape: tuple[int, ...],
1203-
dtype: npt.DTypeLike = None,
1204-
exact: bool = False,
1205-
**kwargs: Any,
1206-
) -> AnyAsyncArray:
1207-
"""Obtain an array, creating if it doesn't exist.
1208-
1209-
!!! warning "Deprecated"
1210-
`AsyncGroup.require_dataset()` is deprecated since v3.0.0 and will be removed in v3.1.0.
1211-
Use `AsyncGroup.require_dataset` instead.
1212-
1213-
Arrays are known as "datasets" in HDF5 terminology. For compatibility
1214-
with h5py, Zarr groups also implement the [zarr.AsyncGroup.create_dataset][] method.
1215-
1216-
Other `kwargs` are as per [zarr.AsyncGroup.create_dataset][].
1217-
1218-
Parameters
1219-
----------
1220-
name : str
1221-
Array name.
1222-
shape : int or tuple of ints
1223-
Array shape.
1224-
dtype : str or dtype, optional
1225-
NumPy dtype.
1226-
exact : bool, optional
1227-
If True, require `dtype` to match exactly. If false, require
1228-
`dtype` can be cast from array dtype.
1229-
1230-
Returns
1231-
-------
1232-
a : AsyncArray
1233-
"""
1234-
return await self.require_array(name, shape=shape, dtype=dtype, exact=exact, **kwargs)
1235-
12361162
async def require_array(
12371163
self,
12381164
name: str,
@@ -1244,7 +1170,7 @@ async def require_array(
12441170
) -> AnyAsyncArray:
12451171
"""Obtain an array, creating if it doesn't exist.
12461172
1247-
Other `kwargs` are as per [zarr.AsyncGroup.create_dataset][].
1173+
Other `kwargs` are as per [zarr.AsyncGroup.create_array][].
12481174
12491175
Parameters
12501176
----------
@@ -2761,57 +2687,6 @@ def create_array(
27612687
)
27622688
)
27632689

2764-
@deprecated("Use Group.create_array instead.", category=ZarrDeprecationWarning)
2765-
def create_dataset(self, name: str, **kwargs: Any) -> AnyArray:
2766-
"""Create an array.
2767-
2768-
!!! warning "Deprecated"
2769-
`Group.create_dataset()` is deprecated since v3.0.0 and will be removed in v3.1.0.
2770-
Use `Group.create_array` instead.
2771-
2772-
2773-
Arrays are known as "datasets" in HDF5 terminology. For compatibility
2774-
with h5py, Zarr groups also implement the [zarr.Group.require_dataset][] method.
2775-
2776-
Parameters
2777-
----------
2778-
name : str
2779-
Array name.
2780-
**kwargs : dict
2781-
Additional arguments passed to [zarr.Group.create_array][]
2782-
2783-
Returns
2784-
-------
2785-
a : Array
2786-
"""
2787-
return Array(self._sync(self._async_group.create_dataset(name, **kwargs)))
2788-
2789-
@deprecated("Use Group.require_array instead.", category=ZarrDeprecationWarning)
2790-
def require_dataset(self, name: str, *, shape: ShapeLike, **kwargs: Any) -> AnyArray:
2791-
"""Obtain an array, creating if it doesn't exist.
2792-
2793-
!!! warning "Deprecated"
2794-
`Group.require_dataset()` is deprecated since v3.0.0 and will be removed in v3.1.0.
2795-
Use `Group.require_array` instead.
2796-
2797-
Arrays are known as "datasets" in HDF5 terminology. For compatibility
2798-
with h5py, Zarr groups also implement the [zarr.Group.create_dataset][] method.
2799-
2800-
Other `kwargs` are as per [zarr.Group.create_dataset][].
2801-
2802-
Parameters
2803-
----------
2804-
name : str
2805-
Array name.
2806-
**kwargs :
2807-
See [zarr.Group.create_dataset][].
2808-
2809-
Returns
2810-
-------
2811-
a : Array
2812-
"""
2813-
return Array(self._sync(self._async_group.require_array(name, shape=shape, **kwargs)))
2814-
28152690
def require_array(self, name: str, *, shape: ShapeLike, **kwargs: Any) -> AnyArray:
28162691
"""Obtain an array, creating if it doesn't exist.
28172692
@@ -3009,152 +2884,6 @@ def move(self, source: str, dest: str) -> None:
30092884
"""
30102885
return self._sync(self._async_group.move(source, dest))
30112886

3012-
@deprecated("Use Group.create_array instead.", category=ZarrDeprecationWarning)
3013-
def array(
3014-
self,
3015-
name: str,
3016-
*,
3017-
shape: ShapeLike,
3018-
dtype: npt.DTypeLike,
3019-
chunks: ChunksLike | Literal["auto"] = "auto",
3020-
shards: tuple[int, ...] | Literal["auto"] | None = None,
3021-
filters: FiltersLike = "auto",
3022-
compressors: CompressorsLike = "auto",
3023-
compressor: CompressorLike = None,
3024-
serializer: SerializerLike = "auto",
3025-
fill_value: Any | None = DEFAULT_FILL_VALUE,
3026-
order: MemoryOrder | None = None,
3027-
attributes: dict[str, JSON] | None = None,
3028-
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
3029-
dimension_names: DimensionNamesLike = None,
3030-
storage_options: dict[str, Any] | None = None,
3031-
overwrite: bool = False,
3032-
config: ArrayConfigLike | None = None,
3033-
data: npt.ArrayLike | None = None,
3034-
) -> AnyArray:
3035-
"""Create an array within this group.
3036-
3037-
!!! warning "Deprecated"
3038-
`Group.array()` is deprecated since v3.0.0 and will be removed in a future release.
3039-
Use `Group.create_array` instead.
3040-
3041-
This method lightly wraps [zarr.core.array.create_array][].
3042-
3043-
Parameters
3044-
----------
3045-
name : str
3046-
The name of the array relative to the group. If ``path`` is ``None``, the array will be located
3047-
at the root of the store.
3048-
shape : tuple[int, ...]
3049-
Shape of the array.
3050-
dtype : npt.DTypeLike
3051-
Data type of the array.
3052-
chunks : tuple[int, ...], optional
3053-
Chunk shape of the array.
3054-
If not specified, default are guessed based on the shape and dtype.
3055-
shards : tuple[int, ...], optional
3056-
Shard shape of the array. The default value of ``None`` results in no sharding at all.
3057-
filters : Iterable[Codec] | Literal["auto"], optional
3058-
Iterable of filters to apply to each chunk of the array, in order, before serializing that
3059-
chunk to bytes.
3060-
3061-
For Zarr format 3, a "filter" is a codec that takes an array and returns an array,
3062-
and these values must be instances of [`zarr.abc.codec.ArrayArrayCodec`][], or a
3063-
dict representations of [`zarr.abc.codec.ArrayArrayCodec`][].
3064-
3065-
For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the
3066-
the order if your filters is consistent with the behavior of each filter.
3067-
3068-
The default value of ``"auto"`` instructs Zarr to use a default used based on the data
3069-
type of the array and the Zarr format specified. For all data types in Zarr V3, and most
3070-
data types in Zarr V2, the default filters are empty. The only cases where default filters
3071-
are not empty is when the Zarr format is 2, and the data type is a variable-length data type like
3072-
[`zarr.dtype.VariableLengthUTF8`][] or [`zarr.dtype.VariableLengthUTF8`][]. In these cases,
3073-
the default filters contains a single element which is a codec specific to that particular data type.
3074-
3075-
To create an array with no filters, provide an empty iterable or the value ``None``.
3076-
compressors : Iterable[Codec], optional
3077-
List of compressors to apply to the array. Compressors are applied in order, and after any
3078-
filters are applied (if any are specified) and the data is serialized into bytes.
3079-
3080-
For Zarr format 3, a "compressor" is a codec that takes a bytestream, and
3081-
returns another bytestream. Multiple compressors my be provided for Zarr format 3.
3082-
If no ``compressors`` are provided, a default set of compressors will be used.
3083-
These defaults can be changed by modifying the value of ``array.v3_default_compressors``
3084-
in [`zarr.config`][zarr.config].
3085-
Use ``None`` to omit default compressors.
3086-
3087-
For Zarr format 2, a "compressor" can be any numcodecs codec. Only a single compressor may
3088-
be provided for Zarr format 2.
3089-
If no ``compressor`` is provided, a default compressor will be used.
3090-
in [`zarr.config`][zarr.config].
3091-
Use ``None`` to omit the default compressor.
3092-
compressor : Codec, optional
3093-
Deprecated in favor of ``compressors``.
3094-
serializer : dict[str, JSON] | ArrayBytesCodec, optional
3095-
Array-to-bytes codec to use for encoding the array data.
3096-
Zarr format 3 only. Zarr format 2 arrays use implicit array-to-bytes conversion.
3097-
If no ``serializer`` is provided, a default serializer will be used.
3098-
These defaults can be changed by modifying the value of ``array.v3_default_serializer``
3099-
in [`zarr.config`][zarr.config].
3100-
fill_value : Any, optional
3101-
Fill value for the array.
3102-
order : {"C", "F"}, optional
3103-
The memory of the array (default is "C").
3104-
For Zarr format 2, this parameter sets the memory order of the array.
3105-
For Zarr format 3, this parameter is deprecated, because memory order
3106-
is a runtime parameter for Zarr format 3 arrays. The recommended way to specify the memory
3107-
order for Zarr format 3 arrays is via the ``config`` parameter, e.g. ``{'config': 'C'}``.
3108-
If no ``order`` is provided, a default order will be used.
3109-
This default can be changed by modifying the value of ``array.order`` in [`zarr.config`][zarr.config].
3110-
attributes : dict, optional
3111-
Attributes for the array.
3112-
chunk_key_encoding : ChunkKeyEncoding, optional
3113-
A specification of how the chunk keys are represented in storage.
3114-
For Zarr format 3, the default is ``{"name": "default", "separator": "/"}}``.
3115-
For Zarr format 2, the default is ``{"name": "v2", "separator": "."}}``.
3116-
dimension_names : Iterable[str], optional
3117-
The names of the dimensions (default is None).
3118-
Zarr format 3 only. Zarr format 2 arrays should not use this parameter.
3119-
storage_options : dict, optional
3120-
If using an fsspec URL to create the store, these will be passed to the backend implementation.
3121-
Ignored otherwise.
3122-
overwrite : bool, default False
3123-
Whether to overwrite an array with the same name in the store, if one exists.
3124-
config : ArrayConfig or ArrayConfigLike, optional
3125-
Runtime configuration for the array.
3126-
data : array_like
3127-
The data to fill the array with.
3128-
3129-
Returns
3130-
-------
3131-
AsyncArray
3132-
"""
3133-
compressors = _parse_deprecated_compressor(compressor, compressors)
3134-
return Array(
3135-
self._sync(
3136-
self._async_group.create_dataset(
3137-
name=name,
3138-
shape=shape,
3139-
dtype=dtype,
3140-
chunks=chunks,
3141-
shards=shards,
3142-
fill_value=fill_value,
3143-
attributes=attributes,
3144-
chunk_key_encoding=chunk_key_encoding,
3145-
compressors=compressors,
3146-
serializer=serializer,
3147-
dimension_names=dimension_names,
3148-
order=order,
3149-
filters=filters,
3150-
overwrite=overwrite,
3151-
storage_options=storage_options,
3152-
config=config,
3153-
data=data,
3154-
)
3155-
)
3156-
)
3157-
31582887

31592888
async def create_hierarchy(
31602889
*,

tests/test_api/test_synchronous.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ def test_docstrings_match(callable_name: str) -> None:
8686
synchronous.create_array,
8787
zarr.AsyncGroup.create_array,
8888
zarr.Group.create_array,
89-
zarr.AsyncGroup.create_dataset,
90-
zarr.Group.create_dataset,
9189
),
9290
),
9391
],

0 commit comments

Comments
 (0)