Skip to content

Commit 066fd3a

Browse files
committed
remove usage of the _deprecate_positional_args decorator, and tests for its behavior
1 parent 0dd797f commit 066fd3a

File tree

7 files changed

+26
-165
lines changed

7 files changed

+26
-165
lines changed

src/zarr/api/synchronous.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import zarr.api.asynchronous as async_api
88
import zarr.core.array
9-
from zarr._compat import _deprecate_positional_args
109
from zarr.core.array import Array, AsyncArray, CompressorLike
1110
from zarr.core.group import Group
1211
from zarr.core.sync import sync
@@ -154,7 +153,6 @@ def load(
154153
)
155154

156155

157-
@_deprecate_positional_args
158156
def open(
159157
store: StoreLike | None = None,
160158
*,
@@ -248,7 +246,6 @@ def save(
248246
)
249247

250248

251-
@_deprecate_positional_args
252249
def save_array(
253250
store: StoreLike,
254251
arr: NDArrayLike,
@@ -380,7 +377,6 @@ def array(data: npt.ArrayLike | Array, **kwargs: Any) -> Array:
380377
return Array(sync(async_api.array(data=data, **kwargs)))
381378

382379

383-
@_deprecate_positional_args
384380
def group(
385381
store: StoreLike | None = None,
386382
*,
@@ -448,7 +444,6 @@ def group(
448444
)
449445

450446

451-
@_deprecate_positional_args
452447
def open_group(
453448
store: StoreLike | None = None,
454449
*,

src/zarr/core/array.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from typing_extensions import deprecated
2727

2828
import zarr
29-
from zarr._compat import _deprecate_positional_args
3029
from zarr.abc.codec import ArrayArrayCodec, ArrayBytesCodec, BytesBytesCodec, Codec
3130
from zarr.abc.store import Store, set_or_delete
3231
from zarr.codecs._v2 import V2Codec
@@ -395,7 +394,6 @@ async def create(
395394

396395
@classmethod
397396
@deprecated("Use zarr.api.asynchronous.create_array instead.")
398-
@_deprecate_positional_args
399397
async def create(
400398
cls,
401399
store: StoreLike,
@@ -1729,7 +1727,6 @@ class Array:
17291727

17301728
@classmethod
17311729
@deprecated("Use zarr.create_array instead.")
1732-
@_deprecate_positional_args
17331730
def create(
17341731
cls,
17351732
store: StoreLike,
@@ -2542,7 +2539,6 @@ def __setitem__(self, selection: Selection, value: npt.ArrayLike) -> None:
25422539
else:
25432540
self.set_basic_selection(cast("BasicSelection", pure_selection), value, fields=fields)
25442541

2545-
@_deprecate_positional_args
25462542
def get_basic_selection(
25472543
self,
25482544
selection: BasicSelection = Ellipsis,
@@ -2666,7 +2662,6 @@ def get_basic_selection(
26662662
)
26672663
)
26682664

2669-
@_deprecate_positional_args
26702665
def set_basic_selection(
26712666
self,
26722667
selection: BasicSelection,
@@ -2762,7 +2757,6 @@ def set_basic_selection(
27622757
indexer = BasicIndexer(selection, self.shape, self.metadata.chunk_grid)
27632758
sync(self._async_array._set_selection(indexer, value, fields=fields, prototype=prototype))
27642759

2765-
@_deprecate_positional_args
27662760
def get_orthogonal_selection(
27672761
self,
27682762
selection: OrthogonalSelection,
@@ -2887,7 +2881,6 @@ def get_orthogonal_selection(
28872881
)
28882882
)
28892883

2890-
@_deprecate_positional_args
28912884
def set_orthogonal_selection(
28922885
self,
28932886
selection: OrthogonalSelection,
@@ -2998,7 +2991,6 @@ def set_orthogonal_selection(
29982991
self._async_array._set_selection(indexer, value, fields=fields, prototype=prototype)
29992992
)
30002993

3001-
@_deprecate_positional_args
30022994
def get_mask_selection(
30032995
self,
30042996
mask: MaskSelection,
@@ -3081,7 +3073,6 @@ def get_mask_selection(
30813073
)
30823074
)
30833075

3084-
@_deprecate_positional_args
30853076
def set_mask_selection(
30863077
self,
30873078
mask: MaskSelection,
@@ -3160,7 +3151,6 @@ def set_mask_selection(
31603151
indexer = MaskIndexer(mask, self.shape, self.metadata.chunk_grid)
31613152
sync(self._async_array._set_selection(indexer, value, fields=fields, prototype=prototype))
31623153

3163-
@_deprecate_positional_args
31643154
def get_coordinate_selection(
31653155
self,
31663156
selection: CoordinateSelection,
@@ -3250,7 +3240,6 @@ def get_coordinate_selection(
32503240
out_array = np.array(out_array).reshape(indexer.sel_shape)
32513241
return out_array
32523242

3253-
@_deprecate_positional_args
32543243
def set_coordinate_selection(
32553244
self,
32563245
selection: CoordinateSelection,
@@ -3348,7 +3337,6 @@ def set_coordinate_selection(
33483337

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

3351-
@_deprecate_positional_args
33523340
def get_block_selection(
33533341
self,
33543342
selection: BasicSelection,
@@ -3447,7 +3435,6 @@ def get_block_selection(
34473435
)
34483436
)
34493437

3450-
@_deprecate_positional_args
34513438
def set_block_selection(
34523439
self,
34533440
selection: BasicSelection,

src/zarr/core/group.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from typing_extensions import deprecated
1717

1818
import zarr.api.asynchronous as async_api
19-
from zarr._compat import _deprecate_positional_args
2019
from zarr.abc.metadata import Metadata
2120
from zarr.abc.store import Store, set_or_delete
2221
from zarr.core._info import GroupInfo
@@ -2366,7 +2365,6 @@ def create(self, *args: Any, **kwargs: Any) -> Array:
23662365
# Backwards compatibility for 2.x
23672366
return self.create_array(*args, **kwargs)
23682367

2369-
@_deprecate_positional_args
23702368
def create_array(
23712369
self,
23722370
name: str,
@@ -2572,7 +2570,6 @@ def require_array(self, name: str, *, shape: ShapeLike, **kwargs: Any) -> Array:
25722570
"""
25732571
return Array(self._sync(self._async_group.require_array(name, shape=shape, **kwargs)))
25742572

2575-
@_deprecate_positional_args
25762573
def empty(self, *, name: str, shape: ChunkCoords, **kwargs: Any) -> Array:
25772574
"""Create an empty array with the specified shape in this Group. The contents will be filled with
25782575
the array's fill value or zeros if no fill value is provided.
@@ -2594,7 +2591,6 @@ def empty(self, *, name: str, shape: ChunkCoords, **kwargs: Any) -> Array:
25942591
"""
25952592
return Array(self._sync(self._async_group.empty(name=name, shape=shape, **kwargs)))
25962593

2597-
@_deprecate_positional_args
25982594
def zeros(self, *, name: str, shape: ChunkCoords, **kwargs: Any) -> Array:
25992595
"""Create an array, with zero being used as the default value for uninitialized portions of the array.
26002596
@@ -2614,7 +2610,6 @@ def zeros(self, *, name: str, shape: ChunkCoords, **kwargs: Any) -> Array:
26142610
"""
26152611
return Array(self._sync(self._async_group.zeros(name=name, shape=shape, **kwargs)))
26162612

2617-
@_deprecate_positional_args
26182613
def ones(self, *, name: str, shape: ChunkCoords, **kwargs: Any) -> Array:
26192614
"""Create an array, with one being used as the default value for uninitialized portions of the array.
26202615
@@ -2634,7 +2629,6 @@ def ones(self, *, name: str, shape: ChunkCoords, **kwargs: Any) -> Array:
26342629
"""
26352630
return Array(self._sync(self._async_group.ones(name=name, shape=shape, **kwargs)))
26362631

2637-
@_deprecate_positional_args
26382632
def full(
26392633
self, *, name: str, shape: ChunkCoords, fill_value: Any | None, **kwargs: Any
26402634
) -> Array:
@@ -2662,7 +2656,6 @@ def full(
26622656
)
26632657
)
26642658

2665-
@_deprecate_positional_args
26662659
def empty_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array:
26672660
"""Create an empty sub-array like `data`. The contents will be filled
26682661
with the array's fill value or zeros if no fill value is provided.
@@ -2689,7 +2682,6 @@ def empty_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) ->
26892682
"""
26902683
return Array(self._sync(self._async_group.empty_like(name=name, data=data, **kwargs)))
26912684

2692-
@_deprecate_positional_args
26932685
def zeros_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array:
26942686
"""Create a sub-array of zeros like `data`.
26952687
@@ -2710,7 +2702,6 @@ def zeros_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) ->
27102702

27112703
return Array(self._sync(self._async_group.zeros_like(name=name, data=data, **kwargs)))
27122704

2713-
@_deprecate_positional_args
27142705
def ones_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array:
27152706
"""Create a sub-array of ones like `data`.
27162707
@@ -2730,7 +2721,6 @@ def ones_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> A
27302721
"""
27312722
return Array(self._sync(self._async_group.ones_like(name=name, data=data, **kwargs)))
27322723

2733-
@_deprecate_positional_args
27342724
def full_like(self, *, name: str, data: async_api.ArrayLike, **kwargs: Any) -> Array:
27352725
"""Create a sub-array like `data` filled with the `fill_value` of `data` .
27362726
@@ -2760,7 +2750,6 @@ def move(self, source: str, dest: str) -> None:
27602750
return self._sync(self._async_group.move(source, dest))
27612751

27622752
@deprecated("Use Group.create_array instead.")
2763-
@_deprecate_positional_args
27642753
def array(
27652754
self,
27662755
name: str,

tests/test_api.py

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from zarr.core.common import JSON, MemoryOrder, ZarrFormat
1414

1515
import contextlib
16-
import warnings
1716
from typing import Literal
1817

1918
import numpy as np
@@ -259,7 +258,7 @@ def test_save_errors() -> None:
259258
save_group("data/group.zarr")
260259
with pytest.raises(TypeError):
261260
# no array provided
262-
save_array("data/group.zarr")
261+
save_array("data/group.zarr") # type: ignore[call-arg]
263262
with pytest.raises(ValueError):
264263
# no arrays provided
265264
save("data/group.zarr")
@@ -1080,40 +1079,6 @@ def test_tree() -> None:
10801079
# copy(source["foo"], dest, dry_run=True, log=True)
10811080

10821081

1083-
def test_open_positional_args_deprecated() -> None:
1084-
store = MemoryStore()
1085-
with pytest.warns(FutureWarning, match="pass"):
1086-
zarr.api.synchronous.open(store, "w", shape=(1,))
1087-
1088-
1089-
def test_save_array_positional_args_deprecated() -> None:
1090-
store = MemoryStore()
1091-
with warnings.catch_warnings():
1092-
warnings.filterwarnings(
1093-
"ignore", message="zarr_version is deprecated", category=DeprecationWarning
1094-
)
1095-
with pytest.warns(FutureWarning, match="pass"):
1096-
save_array(
1097-
store,
1098-
np.ones(
1099-
1,
1100-
),
1101-
3,
1102-
)
1103-
1104-
1105-
def test_group_positional_args_deprecated() -> None:
1106-
store = MemoryStore()
1107-
with pytest.warns(FutureWarning, match="pass"):
1108-
group(store, True)
1109-
1110-
1111-
def test_open_group_positional_args_deprecated() -> None:
1112-
store = MemoryStore()
1113-
with pytest.warns(FutureWarning, match="pass"):
1114-
open_group(store, "w")
1115-
1116-
11171082
def test_open_falls_back_to_open_group() -> None:
11181083
# https://github.com/zarr-developers/zarr-python/issues/2309
11191084
store = MemoryStore()
@@ -1144,9 +1109,9 @@ def test_open_modes_creates_group(tmp_path: pathlib.Path, mode: str) -> None:
11441109
if mode in ["r", "r+"]:
11451110
# Expect FileNotFoundError to be raised if 'r' or 'r+' mode
11461111
with pytest.raises(FileNotFoundError):
1147-
zarr.open(store=zarr_dir, mode=mode)
1112+
zarr.open(store=zarr_dir, mode=mode) # type: ignore[arg-type]
11481113
else:
1149-
group = zarr.open(store=zarr_dir, mode=mode)
1114+
group = zarr.open(store=zarr_dir, mode=mode) # type: ignore[arg-type]
11501115
assert isinstance(group, Group)
11511116

11521117

0 commit comments

Comments
 (0)