Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
79dd9e2
define zarr-specific FutureWarning and DeprecationWarning
d-v-b May 25, 2025
b2e25cf
Merge branch 'main' of github.com:zarr-developers/zarr-python into re…
d-v-b Jun 30, 2025
7c644eb
make unstablespecificationwarning an instance of zarrfuturewarning
d-v-b Jun 30, 2025
c604075
use pytest.warns instead of pytest.raises
d-v-b Jun 30, 2025
b964ff6
Merge branch 'main' into refactor-warnings
d-v-b Jul 11, 2025
12bea9c
Merge branch 'main' into refactor-warnings
d-v-b Jul 11, 2025
8267c0c
Merge branch 'main' into refactor-warnings
d-v-b Jul 11, 2025
702ef09
Merge branch 'main' of https://github.com/zarr-developers/zarr-python…
d-v-b Jul 31, 2025
64e1405
changelog
d-v-b Jul 31, 2025
d322cad
ensure that all deprecations are ZarrDeprecations
d-v-b Aug 1, 2025
31e63aa
add docstrings and export warnings
d-v-b Aug 1, 2025
917fd3d
fix imports
d-v-b Aug 1, 2025
9055d3b
handle warnings in tests explicitly; make userwarnings ZarrUserWarning
d-v-b Aug 1, 2025
fee48d3
fix doctests by making them more realistic
d-v-b Aug 1, 2025
6a208eb
lint and fix typo
d-v-b Aug 1, 2025
8a2bb9e
Merge branch 'main' into refactor-warnings
d-v-b Aug 1, 2025
a235660
move unstable spec warning to errors
d-v-b Aug 1, 2025
8afdce9
Merge branch 'refactor-warnings' of https://github.com/d-v-b/zarr-pyt…
d-v-b Aug 1, 2025
33a9184
handle warnings in gpu tests
d-v-b Aug 1, 2025
fc72752
handle more warnings
d-v-b Aug 1, 2025
42b4cb5
handle another warning
d-v-b Aug 1, 2025
713bda9
Fix exports
d-v-b Aug 1, 2025
f483eb8
Update src/zarr/errors.py
d-v-b Aug 2, 2025
d029800
Update changes/3098.misc.rst
d-v-b Aug 2, 2025
94ab461
Merge branch 'main' into refactor-warnings
d-v-b Aug 4, 2025
c11328b
Merge branch 'main' into refactor-warnings
d-v-b Aug 4, 2025
fd76671
Merge branch 'main' into refactor-warnings
d-v-b Aug 4, 2025
b7861b7
Merge branch 'main' into refactor-warnings
d-v-b Aug 5, 2025
ba5be4f
Update src/zarr/errors.py
d-v-b Aug 5, 2025
df0eef4
add test to ensure that ambiguous group.open warns
d-v-b Aug 5, 2025
61ff062
update changelog
d-v-b Aug 5, 2025
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
Prev Previous commit
Next Next commit
…into refactor-warnings
  • Loading branch information
d-v-b committed Jul 31, 2025
commit 702ef093b67e0fbdbcac2b0049fe36f7359bfb37
6 changes: 2 additions & 4 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ async def create(
) -> AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]: ...

@classmethod
@deprecated("Use zarr.api.asynchronous.create_array instead.", category=ZarrDeprecationWarning)
@_deprecate_positional_args
@deprecated("Use zarr.api.asynchronous.create_array instead.")
async def create(
cls,
store: StoreLike,
Expand Down Expand Up @@ -1856,8 +1855,7 @@ class Array:
_async_array: AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]

@classmethod
@deprecated("Use zarr.create_array instead.", category=ZarrDeprecationWarning)
@_deprecate_positional_args
@deprecated("Use zarr.create_array instead.")
def create(
cls,
store: StoreLike,
Expand Down
3 changes: 1 addition & 2 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2828,8 +2828,7 @@ 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)
@_deprecate_positional_args
@deprecated("Use Group.create_array instead.")
def array(
self,
name: str,
Expand Down
40 changes: 4 additions & 36 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import zarr.codecs
import zarr.storage
from zarr.core.array import init_array
from zarr.storage._common import StorePath
from zarr.storage._local import LocalStore
from zarr.storage._zip import ZipStore

Expand Down Expand Up @@ -41,7 +43,7 @@
save_group,
)
from zarr.core.buffer import NDArrayLike
from zarr.errors import MetadataValidationError, ZarrDeprecationWarning, ZarrFutureWarning
from zarr.errors import MetadataValidationError, ZarrDeprecationWarning
from zarr.storage import MemoryStore
from zarr.storage._utils import normalize_path
from zarr.testing.utils import gpu_test
Expand Down Expand Up @@ -470,7 +472,7 @@ 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):
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())

Expand Down Expand Up @@ -1142,40 +1144,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(ZarrFutureWarning, 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=ZarrDeprecationWarning
)
with pytest.warns(ZarrFutureWarning, match="pass"):
save_array(
store,
np.ones(
1,
),
3,
)


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


def test_open_group_positional_args_deprecated() -> None:
store = MemoryStore()
with pytest.warns(ZarrFutureWarning, 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
46 changes: 0 additions & 46 deletions tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
from zarr.errors import (
ContainsArrayError,
ContainsGroupError,
ZarrDeprecationWarning,
ZarrFutureWarning,
)
from zarr.storage import LocalStore, MemoryStore, StorePath

Expand Down Expand Up @@ -261,50 +259,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(ZarrDeprecationWarning):
with pytest.warns(ZarrFutureWarning, 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(ZarrDeprecationWarning):
with pytest.warns(ZarrFutureWarning, 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(ZarrFutureWarning, match="Pass out"):
arr.get_basic_selection(..., NDBuffer(array=np.empty((2, 2))))

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

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

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

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

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

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

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

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

with pytest.warns(ZarrFutureWarning, 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
42 changes: 14 additions & 28 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
ContainsGroupError,
MetadataValidationError,
ZarrDeprecationWarning,
ZarrFutureWarning,
)
from zarr.storage import LocalStore, MemoryStore, StorePath, ZipStore
from zarr.storage._common import make_store_path
Expand Down Expand Up @@ -654,7 +653,7 @@ def test_group_create_array(
array = group.create_array(name=name, shape=shape, dtype=dtype)
array[:] = data
elif method == "array":
with pytest.warns(ZarrDeprecationWarning):
with pytest.warns(ZarrDeprecationWarning, match=r"Group\.create_array instead\."):
array = group.array(name=name, data=data, shape=shape, dtype=dtype)
else:
raise AssertionError
Expand All @@ -665,8 +664,9 @@ def test_group_create_array(
a = group.create_array(name=name, shape=shape, dtype=dtype)
a[:] = data
elif method == "array":
with pytest.raises(ContainsArrayError), pytest.warns(ZarrDeprecationWarning):
a = group.array(name=name, shape=shape, dtype=dtype)
with pytest.raises(ContainsArrayError): # noqa: PT012
with pytest.warns(ZarrDeprecationWarning, match=r"Group\.create_array instead\."):
a = group.array(name=name, shape=shape, dtype=dtype)
a[:] = data

assert array.path == normalize_path(name)
Expand Down Expand Up @@ -1199,22 +1199,28 @@ def test_create_dataset_with_data(store: Store, zarr_format: ZarrFormat) -> None
"""
root = Group.from_store(store=store, zarr_format=zarr_format)
arr = np.random.random((5, 5))
with pytest.warns(ZarrDeprecationWarning):
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):
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):
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):
with (
pytest.raises(ContainsGroupError),
pytest.warns(ZarrDeprecationWarning, match=r"Group\.create_array instead\."),
):
await root.create_dataset("bar", shape=(100,), dtype="int8")


Expand Down Expand Up @@ -1462,26 +1468,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(ZarrFutureWarning, 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(ZarrFutureWarning, 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
8 changes: 0 additions & 8 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
loop,
sync,
)
from zarr.errors import ZarrFutureWarning
from zarr.storage import MemoryStore


@pytest.fixture(params=[True, False])
Expand Down Expand Up @@ -144,12 +142,6 @@ def bar(self) -> list[int]:
assert foo.bar() == list(range(10))


def test_open_positional_args_deprecate():
store = MemoryStore()
with pytest.warns(ZarrFutureWarning, match="pass"):
zarr.open(store, "w", shape=(1,))


@pytest.mark.parametrize("workers", [None, 1, 2])
def test_threadpool_executor(clean_state, workers: int | None) -> None:
with zarr.config.set({"threading.max_workers": workers}):
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.