Skip to content

remove usage of the _deprecate_positional_args decorator, and tests for its behavior #3225

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 6 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
5 changes: 0 additions & 5 deletions src/zarr/api/synchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import zarr.api.asynchronous as async_api
import zarr.core.array
from zarr._compat import _deprecate_positional_args
from zarr.core.array import DEFAULT_FILL_VALUE, Array, AsyncArray, CompressorLike
from zarr.core.group import Group
from zarr.core.sync import sync
Expand Down Expand Up @@ -160,7 +159,6 @@ def load(
)


@_deprecate_positional_args
def open(
store: StoreLike | None = None,
*,
Expand Down Expand Up @@ -255,7 +253,6 @@ def save(
)


@_deprecate_positional_args
def save_array(
store: StoreLike,
arr: NDArrayLike,
Expand Down Expand Up @@ -387,7 +384,6 @@ def array(data: npt.ArrayLike | Array, **kwargs: Any) -> Array:
return Array(sync(async_api.array(data=data, **kwargs)))


@_deprecate_positional_args
def group(
store: StoreLike | None = None,
*,
Expand Down Expand Up @@ -455,7 +451,6 @@ def group(
)


@_deprecate_positional_args
def open_group(
store: StoreLike | None = None,
*,
Expand Down
13 changes: 0 additions & 13 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from typing_extensions import deprecated

import zarr
from zarr._compat import _deprecate_positional_args
from zarr.abc.codec import ArrayArrayCodec, ArrayBytesCodec, BytesBytesCodec, Codec
from zarr.abc.store import Store, set_or_delete
from zarr.codecs._v2 import V2Codec
Expand Down Expand Up @@ -430,7 +429,6 @@ async def create(

@classmethod
@deprecated("Use zarr.api.asynchronous.create_array instead.")
@_deprecate_positional_args
async def create(
cls,
store: StoreLike,
Expand Down Expand Up @@ -1782,7 +1780,6 @@ class Array:

@classmethod
@deprecated("Use zarr.create_array instead.")
@_deprecate_positional_args
def create(
cls,
store: StoreLike,
Expand Down Expand Up @@ -2595,7 +2592,6 @@ def __setitem__(self, selection: Selection, value: npt.ArrayLike) -> None:
else:
self.set_basic_selection(cast("BasicSelection", pure_selection), value, fields=fields)

@_deprecate_positional_args
def get_basic_selection(
self,
selection: BasicSelection = Ellipsis,
Expand Down Expand Up @@ -2719,7 +2715,6 @@ def get_basic_selection(
)
)

@_deprecate_positional_args
def set_basic_selection(
self,
selection: BasicSelection,
Expand Down Expand Up @@ -2815,7 +2810,6 @@ def set_basic_selection(
indexer = BasicIndexer(selection, self.shape, self.metadata.chunk_grid)
sync(self._async_array._set_selection(indexer, value, fields=fields, prototype=prototype))

@_deprecate_positional_args
def get_orthogonal_selection(
self,
selection: OrthogonalSelection,
Expand Down Expand Up @@ -2940,7 +2934,6 @@ def get_orthogonal_selection(
)
)

@_deprecate_positional_args
def set_orthogonal_selection(
self,
selection: OrthogonalSelection,
Expand Down Expand Up @@ -3051,7 +3044,6 @@ def set_orthogonal_selection(
self._async_array._set_selection(indexer, value, fields=fields, prototype=prototype)
)

@_deprecate_positional_args
def get_mask_selection(
self,
mask: MaskSelection,
Expand Down Expand Up @@ -3134,7 +3126,6 @@ def get_mask_selection(
)
)

@_deprecate_positional_args
def set_mask_selection(
self,
mask: MaskSelection,
Expand Down Expand Up @@ -3213,7 +3204,6 @@ def set_mask_selection(
indexer = MaskIndexer(mask, self.shape, self.metadata.chunk_grid)
sync(self._async_array._set_selection(indexer, value, fields=fields, prototype=prototype))

@_deprecate_positional_args
def get_coordinate_selection(
self,
selection: CoordinateSelection,
Expand Down Expand Up @@ -3303,7 +3293,6 @@ def get_coordinate_selection(
out_array = np.array(out_array).reshape(indexer.sel_shape)
return out_array

@_deprecate_positional_args
def set_coordinate_selection(
self,
selection: CoordinateSelection,
Expand Down Expand Up @@ -3401,7 +3390,6 @@ def set_coordinate_selection(

sync(self._async_array._set_selection(indexer, value, fields=fields, prototype=prototype))

@_deprecate_positional_args
def get_block_selection(
self,
selection: BasicSelection,
Expand Down Expand Up @@ -3500,7 +3488,6 @@ def get_block_selection(
)
)

@_deprecate_positional_args
def set_block_selection(
self,
selection: BasicSelection,
Expand Down
11 changes: 0 additions & 11 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
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._info import GroupInfo
Expand Down Expand Up @@ -2417,7 +2416,6 @@ 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,
Expand Down Expand Up @@ -2635,7 +2633,6 @@ def require_array(self, name: str, *, shape: ShapeLike, **kwargs: Any) -> Array:
"""
return Array(self._sync(self._async_group.require_array(name, shape=shape, **kwargs)))

@_deprecate_positional_args
def empty(self, *, name: str, shape: ChunkCoords, **kwargs: Any) -> Array:
"""Create an empty array with the specified shape in this Group. The contents will be filled with
the array's fill value or zeros if no fill value is provided.
Expand All @@ -2657,7 +2654,6 @@ 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:
"""Create an array, with zero being used as the default value for uninitialized portions of the array.

Expand All @@ -2677,7 +2673,6 @@ 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:
"""Create an array, with one being used as the default value for uninitialized portions of the array.

Expand All @@ -2697,7 +2692,6 @@ 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:
Expand Down Expand Up @@ -2725,7 +2719,6 @@ def full(
)
)

@_deprecate_positional_args
def empty_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array:
"""Create an empty sub-array like `data`. The contents will be filled
with the array's fill value or zeros if no fill value is provided.
Expand All @@ -2752,7 +2745,6 @@ def empty_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) ->
"""
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:
"""Create a sub-array of zeros like `data`.

Expand All @@ -2773,7 +2765,6 @@ def zeros_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) ->

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:
"""Create a sub-array of ones like `data`.

Expand All @@ -2793,7 +2784,6 @@ def ones_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> A
"""
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:
"""Create a sub-array like `data` filled with the `fill_value` of `data` .

Expand Down Expand Up @@ -2823,7 +2813,6 @@ 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,
Expand Down
41 changes: 3 additions & 38 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from zarr.core.common import JSON, MemoryOrder, ZarrFormat

import contextlib
import warnings
from typing import Literal

import numpy as np
Expand Down Expand Up @@ -263,7 +262,7 @@ def test_save_errors() -> None:
save_group("data/group.zarr")
with pytest.raises(TypeError):
# no array provided
save_array("data/group.zarr")
save_array("data/group.zarr") # type: ignore[call-arg]
with pytest.raises(ValueError):
# no arrays provided
save("data/group.zarr")
Expand Down Expand Up @@ -1116,40 +1115,6 @@ def test_tree() -> None:
# copy(source["foo"], dest, dry_run=True, log=True)


def test_open_positional_args_deprecated() -> None:
store = MemoryStore()
with pytest.warns(FutureWarning, match="pass"):
zarr.api.synchronous.open(store, "w", shape=(1,))


def test_save_array_positional_args_deprecated() -> None:
store = MemoryStore()
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", message="zarr_version is deprecated", category=DeprecationWarning
)
with pytest.warns(FutureWarning, match="pass"):
save_array(
store,
np.ones(
1,
),
3,
)


def test_group_positional_args_deprecated() -> None:
store = MemoryStore()
with pytest.warns(FutureWarning, match="pass"):
group(store, True)


def test_open_group_positional_args_deprecated() -> None:
store = MemoryStore()
with pytest.warns(FutureWarning, match="pass"):
open_group(store, "w")


def test_open_falls_back_to_open_group() -> None:
# https://github.com/zarr-developers/zarr-python/issues/2309
store = MemoryStore()
Expand Down Expand Up @@ -1180,9 +1145,9 @@ def test_open_modes_creates_group(tmp_path: pathlib.Path, mode: str) -> None:
if mode in ["r", "r+"]:
# Expect FileNotFoundError to be raised if 'r' or 'r+' mode
with pytest.raises(FileNotFoundError):
zarr.open(store=zarr_dir, mode=mode)
zarr.open(store=zarr_dir, mode=mode) # type: ignore[arg-type]
else:
group = zarr.open(store=zarr_dir, mode=mode)
group = zarr.open(store=zarr_dir, mode=mode) # type: ignore[arg-type]
assert isinstance(group, Group)


Expand Down
45 changes: 0 additions & 45 deletions tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
default_serializer_v3,
)
from zarr.core.buffer import NDArrayLike, NDArrayLikeOrScalar, default_buffer_prototype
from zarr.core.buffer.cpu import NDBuffer
from zarr.core.chunk_grids import _auto_partition
from zarr.core.chunk_key_encodings import ChunkKeyEncodingParams
from zarr.core.common import JSON, MemoryOrder, ZarrFormat
Expand Down Expand Up @@ -257,50 +256,6 @@ def test_array_v3_fill_value(store: MemoryStore, fill_value: int, dtype_str: str
assert arr.fill_value.dtype == arr.dtype


async def test_create_deprecated() -> None:
with pytest.warns(DeprecationWarning):
with pytest.warns(FutureWarning, match=re.escape("Pass shape=(2, 2) as keyword args")):
await zarr.AsyncArray.create(MemoryStore(), (2, 2), dtype="f8") # type: ignore[call-overload]
with pytest.warns(DeprecationWarning):
with pytest.warns(FutureWarning, match=re.escape("Pass shape=(2, 2) as keyword args")):
zarr.Array.create(MemoryStore(), (2, 2), dtype="f8")


def test_selection_positional_args_deprecated() -> None:
store = MemoryStore()
arr = zarr.create_array(store, shape=(2, 2), dtype="f8")

with pytest.warns(FutureWarning, match="Pass out"):
arr.get_basic_selection(..., NDBuffer(array=np.empty((2, 2))))

with pytest.warns(FutureWarning, match="Pass fields"):
arr.set_basic_selection(..., 1, None)

with pytest.warns(FutureWarning, match="Pass out"):
arr.get_orthogonal_selection(..., NDBuffer(array=np.empty((2, 2))))

with pytest.warns(FutureWarning, match="Pass"):
arr.set_orthogonal_selection(..., 1, None)

with pytest.warns(FutureWarning, match="Pass"):
arr.get_mask_selection(np.zeros((2, 2), dtype=bool), NDBuffer(array=np.empty((0,))))

with pytest.warns(FutureWarning, match="Pass"):
arr.set_mask_selection(np.zeros((2, 2), dtype=bool), 1, None)

with pytest.warns(FutureWarning, match="Pass"):
arr.get_coordinate_selection(([0, 1], [0, 1]), NDBuffer(array=np.empty((2,))))

with pytest.warns(FutureWarning, match="Pass"):
arr.set_coordinate_selection(([0, 1], [0, 1]), 1, None)

with pytest.warns(FutureWarning, match="Pass"):
arr.get_block_selection((0, slice(None)), NDBuffer(array=np.empty((2, 2))))

with pytest.warns(FutureWarning, match="Pass"):
arr.set_block_selection((0, slice(None)), 1, None)


@pytest.mark.parametrize("store", ["memory"], indirect=True)
async def test_array_v3_nan_fill_value(store: MemoryStore) -> None:
shape = (10,)
Expand Down
20 changes: 0 additions & 20 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,26 +1446,6 @@ def test_update_attrs() -> None:
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


@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"])
def test_delitem_removes_children(store: Store, zarr_format: ZarrFormat) -> None:
# https://github.com/zarr-developers/zarr-python/issues/2191
Expand Down
Loading
Loading