diff --git a/src/zarr/core/group.py b/src/zarr/core/group.py index ba6821357..6e54b7ec9 100644 --- a/src/zarr/core/group.py +++ b/src/zarr/core/group.py @@ -14,6 +14,7 @@ from typing_extensions import deprecated import zarr.api.asynchronous as async_api +from zarr._compat import _deprecate_positional_args from zarr.abc.metadata import Metadata from zarr.abc.store import Store, set_or_delete from zarr.core.array import Array, AsyncArray, _build_parents @@ -1531,6 +1532,7 @@ def create(self, *args: Any, **kwargs: Any) -> Array: # Backwards compatibility for 2.x return self.create_array(*args, **kwargs) + @_deprecate_positional_args def create_array( self, name: str, @@ -1692,15 +1694,19 @@ def require_array(self, name: str, **kwargs: Any) -> Array: """ return Array(self._sync(self._async_group.require_array(name, **kwargs))) + @_deprecate_positional_args def empty(self, *, name: str, shape: ChunkCoords, **kwargs: Any) -> Array: return Array(self._sync(self._async_group.empty(name=name, shape=shape, **kwargs))) + @_deprecate_positional_args def zeros(self, *, name: str, shape: ChunkCoords, **kwargs: Any) -> Array: return Array(self._sync(self._async_group.zeros(name=name, shape=shape, **kwargs))) + @_deprecate_positional_args def ones(self, *, name: str, shape: ChunkCoords, **kwargs: Any) -> Array: return Array(self._sync(self._async_group.ones(name=name, shape=shape, **kwargs))) + @_deprecate_positional_args def full( self, *, name: str, shape: ChunkCoords, fill_value: Any | None, **kwargs: Any ) -> Array: @@ -1710,15 +1716,19 @@ def full( ) ) + @_deprecate_positional_args def empty_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array: return Array(self._sync(self._async_group.empty_like(name=name, data=data, **kwargs))) + @_deprecate_positional_args def zeros_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array: return Array(self._sync(self._async_group.zeros_like(name=name, data=data, **kwargs))) + @_deprecate_positional_args def ones_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array: return Array(self._sync(self._async_group.ones_like(name=name, data=data, **kwargs))) + @_deprecate_positional_args def full_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array: return Array(self._sync(self._async_group.full_like(name=name, data=data, **kwargs))) @@ -1726,6 +1736,7 @@ def move(self, source: str, dest: str) -> None: return self._sync(self._async_group.move(source, dest)) @deprecated("Use Group.create_array instead.") + @_deprecate_positional_args def array( self, name: str, diff --git a/tests/test_group.py b/tests/test_group.py index f4063f6ef..21e4ef4e5 100644 --- a/tests/test_group.py +++ b/tests/test_group.py @@ -1334,3 +1334,23 @@ def test_update_attrs() -> None: ) root.attrs["foo"] = "bar" assert root.attrs["foo"] == "bar" + + +@pytest.mark.parametrize("method", ["empty", "zeros", "ones", "full"]) +def test_group_deprecated_positional_args(method: str) -> None: + if method == "full": + kwargs = {"fill_value": 0} + else: + kwargs = {} + + root = zarr.group() + with pytest.warns(FutureWarning, match=r"Pass name=.* as keyword args."): + arr = getattr(root, method)("foo", shape=1, **kwargs) + assert arr.shape == (1,) + + method += "_like" + data = np.ones(1) + + with pytest.warns(FutureWarning, match=r"Pass name=.*, data=.* as keyword args."): + arr = getattr(root, method)("foo_like", data, **kwargs) + assert arr.shape == data.shape