Skip to content

refactor warnings #3098

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ filterwarnings = [
"ignore:Automatic shard shape inference is experimental and may change without notice.*:UserWarning",
"ignore:The codec .* is currently not part in the Zarr format 3 specification.*:UserWarning",
"ignore:The dtype .* is currently not part in the Zarr format 3 specification.*:UserWarning",
"ignore:Use zarr.create_array instead.:DeprecationWarning",
"ignore:Use zarr.create_array instead.:zarr.errors.ZarrDeprecationWarning",
"ignore:Duplicate name.*:UserWarning",
"ignore:The `compressor` argument is deprecated. Use `compressors` instead.:UserWarning",
"ignore:Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations.:UserWarning",
Expand Down
4 changes: 3 additions & 1 deletion src/zarr/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from inspect import Parameter, signature
from typing import Any, TypeVar

from zarr.errors import ZarrFutureWarning

Check warning on line 7 in src/zarr/_compat.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/_compat.py#L7

Added line #L7 was not covered by tests

T = TypeVar("T")

# Based off https://github.com/scikit-learn/scikit-learn/blob/e87b32a81c70abed8f2e97483758eb64df8255e9/sklearn/utils/validation.py#L63
Expand Down Expand Up @@ -54,7 +56,7 @@
f"{version} passing these as positional arguments "
"will result in an error"
),
FutureWarning,
ZarrFutureWarning,
stacklevel=2,
)
kwargs.update(zip(sig.parameters, args, strict=False))
Expand Down
6 changes: 3 additions & 3 deletions src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
)
from zarr.core.metadata import ArrayMetadataDict, ArrayV2Metadata, ArrayV3Metadata
from zarr.core.metadata.v2 import _default_compressor, _default_filters
from zarr.errors import NodeTypeValidationError
from zarr.errors import NodeTypeValidationError, ZarrDeprecationWarning

Check warning on line 42 in src/zarr/api/asynchronous.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/api/asynchronous.py#L42

Added line #L42 was not covered by tests
from zarr.storage._common import make_store_path

if TYPE_CHECKING:
Expand Down Expand Up @@ -159,7 +159,7 @@
)
if zarr_version is not None:
warnings.warn(
"zarr_version is deprecated, use zarr_format", DeprecationWarning, stacklevel=2
"zarr_version is deprecated, use zarr_format", ZarrDeprecationWarning, stacklevel=2
)
return zarr_version
return zarr_format
Expand Down Expand Up @@ -517,7 +517,7 @@
await asyncio.gather(*aws)


@deprecated("Use AsyncGroup.tree instead.")
@deprecated("Use AsyncGroup.tree instead.", category=ZarrDeprecationWarning)

Check warning on line 520 in src/zarr/api/asynchronous.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/api/asynchronous.py#L520

Added line #L520 was not covered by tests
async def tree(grp: AsyncGroup, expand: bool | None = None, level: int | None = None) -> Any:
"""Provide a rich display of the hierarchy.

Expand Down
3 changes: 2 additions & 1 deletion src/zarr/api/synchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from zarr.core.group import Group
from zarr.core.sync import sync
from zarr.core.sync_group import create_hierarchy
from zarr.errors import ZarrDeprecationWarning

Check warning on line 14 in src/zarr/api/synchronous.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/api/synchronous.py#L14

Added line #L14 was not covered by tests

if TYPE_CHECKING:
from collections.abc import Iterable
Expand Down Expand Up @@ -335,7 +336,7 @@
)


@deprecated("Use Group.tree instead.")
@deprecated("Use Group.tree instead.", category=ZarrDeprecationWarning)

Check warning on line 339 in src/zarr/api/synchronous.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/api/synchronous.py#L339

Added line #L339 was not covered by tests
def tree(grp: Group, expand: bool | None = None, level: int | None = None) -> Any:
"""Provide a rich display of the hierarchy.

Expand Down
3 changes: 2 additions & 1 deletion src/zarr/convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
save_group,
tree,
)
from zarr.errors import ZarrDeprecationWarning

Check warning on line 25 in src/zarr/convenience.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/convenience.py#L25

Added line #L25 was not covered by tests

__all__ = [
"consolidate_metadata",
Expand All @@ -40,6 +41,6 @@
warnings.warn(
"zarr.convenience is deprecated. "
"Import these functions from the top level zarr. namespace instead.",
DeprecationWarning,
ZarrDeprecationWarning,
stacklevel=2,
)
10 changes: 5 additions & 5 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
)
from zarr.core.metadata.v3 import DataType, parse_node_type_array
from zarr.core.sync import sync
from zarr.errors import MetadataValidationError
from zarr.errors import MetadataValidationError, ZarrDeprecationWarning

Check warning on line 113 in src/zarr/core/array.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/array.py#L113

Added line #L113 was not covered by tests
from zarr.registry import (
_parse_array_array_codec,
_parse_array_bytes_codec,
Expand Down Expand Up @@ -394,7 +394,7 @@
) -> AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]: ...

@classmethod
@deprecated("Use zarr.api.asynchronous.create_array instead.")
@deprecated("Use zarr.api.asynchronous.create_array instead.", category=ZarrDeprecationWarning)

Check warning on line 397 in src/zarr/core/array.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/array.py#L397

Added line #L397 was not covered by tests
@_deprecate_positional_args
async def create(
cls,
Expand Down Expand Up @@ -1002,7 +1002,7 @@
)

@property
@deprecated("Use AsyncArray.compressors instead.")
@deprecated("Use AsyncArray.compressors instead.", category=ZarrDeprecationWarning)

Check warning on line 1005 in src/zarr/core/array.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/array.py#L1005

Added line #L1005 was not covered by tests
def compressor(self) -> numcodecs.abc.Codec | None:
"""
Compressor that is applied to each chunk of the array.
Expand Down Expand Up @@ -1727,7 +1727,7 @@
_async_array: AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]

@classmethod
@deprecated("Use zarr.create_array instead.")
@deprecated("Use zarr.create_array instead.", category=ZarrDeprecationWarning)

Check warning on line 1730 in src/zarr/core/array.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/array.py#L1730

Added line #L1730 was not covered by tests
@_deprecate_positional_args
def create(
cls,
Expand Down Expand Up @@ -2115,7 +2115,7 @@
return self._async_array.serializer

@property
@deprecated("Use Array.compressors instead.")
@deprecated("Use Array.compressors instead.", category=ZarrDeprecationWarning)

Check warning on line 2118 in src/zarr/core/array.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/array.py#L2118

Added line #L2118 was not covered by tests
def compressor(self) -> numcodecs.abc.Codec | None:
"""
Compressor that is applied to each chunk of the array.
Expand Down
17 changes: 11 additions & 6 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@
from zarr.core.metadata import ArrayV2Metadata, ArrayV3Metadata
from zarr.core.metadata.v3 import V3JsonEncoder, _replace_special_floats
from zarr.core.sync import SyncMixin, sync
from zarr.errors import ContainsArrayError, ContainsGroupError, MetadataValidationError
from zarr.errors import (

Check warning on line 56 in src/zarr/core/group.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/group.py#L56

Added line #L56 was not covered by tests
ContainsArrayError,
ContainsGroupError,
MetadataValidationError,
ZarrDeprecationWarning,
)
from zarr.storage import StoreLike, StorePath
from zarr.storage._common import ensure_no_existing_node, make_store_path
from zarr.storage._utils import _join_paths, _normalize_path_keys, normalize_path
Expand Down Expand Up @@ -1128,7 +1133,7 @@
config=config,
)

@deprecated("Use AsyncGroup.create_array instead.")
@deprecated("Use AsyncGroup.create_array instead.", category=ZarrDeprecationWarning)

Check warning on line 1136 in src/zarr/core/group.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/group.py#L1136

Added line #L1136 was not covered by tests
async def create_dataset(
self, name: str, *, shape: ShapeLike, **kwargs: Any
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
Expand Down Expand Up @@ -1162,7 +1167,7 @@
await array.setitem(slice(None), data)
return array

@deprecated("Use AsyncGroup.require_array instead.")
@deprecated("Use AsyncGroup.require_array instead.", category=ZarrDeprecationWarning)

Check warning on line 1170 in src/zarr/core/group.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/group.py#L1170

Added line #L1170 was not covered by tests
async def require_dataset(
self,
name: str,
Expand Down Expand Up @@ -2504,7 +2509,7 @@
)
)

@deprecated("Use Group.create_array instead.")
@deprecated("Use Group.create_array instead.", category=ZarrDeprecationWarning)

Check warning on line 2512 in src/zarr/core/group.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/group.py#L2512

Added line #L2512 was not covered by tests
def create_dataset(self, name: str, **kwargs: Any) -> Array:
"""Create an array.

Expand All @@ -2528,7 +2533,7 @@
"""
return Array(self._sync(self._async_group.create_dataset(name, **kwargs)))

@deprecated("Use Group.require_array instead.")
@deprecated("Use Group.require_array instead.", category=ZarrDeprecationWarning)

Check warning on line 2536 in src/zarr/core/group.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/group.py#L2536

Added line #L2536 was not covered by tests
def require_dataset(self, name: str, *, shape: ShapeLike, **kwargs: Any) -> Array:
"""Obtain an array, creating if it doesn't exist.

Expand Down Expand Up @@ -2758,7 +2763,7 @@
"""
return self._sync(self._async_group.move(source, dest))

@deprecated("Use Group.create_array instead.")
@deprecated("Use Group.create_array instead.", category=ZarrDeprecationWarning)

Check warning on line 2766 in src/zarr/core/group.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/group.py#L2766

Added line #L2766 was not covered by tests
@_deprecate_positional_args
def array(
self,
Expand Down
3 changes: 2 additions & 1 deletion src/zarr/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
zeros,
zeros_like,
)
from zarr.errors import ZarrDeprecationWarning

Check warning on line 26 in src/zarr/creation.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/creation.py#L26

Added line #L26 was not covered by tests

__all__ = [
"array",
Expand All @@ -42,6 +43,6 @@
warnings.warn(
"zarr.creation is deprecated. "
"Import these functions from the top level zarr. namespace instead.",
DeprecationWarning,
ZarrDeprecationWarning,
stacklevel=2,
)
6 changes: 6 additions & 0 deletions src/zarr/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ class NodeTypeValidationError(MetadataValidationError):
This can be raised when the value is invalid or unexpected given the context,
for example an 'array' node when we expected a 'group'.
"""


class ZarrFutureWarning(FutureWarning): ...


class ZarrDeprecationWarning(DeprecationWarning): ...
3 changes: 2 additions & 1 deletion src/zarr/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from types import ModuleType
from typing import Any

from zarr.errors import ZarrDeprecationWarning

Check warning on line 6 in src/zarr/storage/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/storage/__init__.py#L6

Added line #L6 was not covered by tests
from zarr.storage._common import StoreLike, StorePath
from zarr.storage._fsspec import FsspecStore
from zarr.storage._local import LocalStore
Expand Down Expand Up @@ -33,7 +34,7 @@
"setting zarr.storage.default_compressor is deprecated, use "
"zarr.config to configure array.v2_default_compressor "
"e.g. config.set({'codecs.zstd':'numcodecs.Zstd', 'array.v2_default_compressor.numeric': 'zstd'})",
DeprecationWarning,
ZarrDeprecationWarning,
stacklevel=1,
)
else:
Expand Down
14 changes: 7 additions & 7 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
save_group,
)
from zarr.core.buffer import NDArrayLike
from zarr.errors import MetadataValidationError
from zarr.errors import MetadataValidationError, ZarrDeprecationWarning, ZarrFutureWarning
from zarr.storage import MemoryStore
from zarr.storage._utils import normalize_path
from zarr.testing.utils import gpu_test
Expand Down Expand Up @@ -408,7 +408,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(DeprecationWarning):
with pytest.warns(ZarrDeprecationWarning):
assert repr(zarr.tree(g1)) == repr(g1.tree())
assert str(zarr.tree(g1)) == str(g1.tree())

Expand Down Expand Up @@ -1082,17 +1082,17 @@ def test_tree() -> None:

def test_open_positional_args_deprecated() -> None:
store = MemoryStore()
with pytest.warns(FutureWarning, match="pass"):
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=DeprecationWarning
"ignore", message="zarr_version is deprecated", category=ZarrDeprecationWarning
)
with pytest.warns(FutureWarning, match="pass"):
with pytest.warns(ZarrFutureWarning, match="pass"):
save_array(
store,
np.ones(
Expand All @@ -1104,13 +1104,13 @@ def test_save_array_positional_args_deprecated() -> None:

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


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


Expand Down
35 changes: 20 additions & 15 deletions tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@
from zarr.core.indexing import BasicIndexer, ceildiv
from zarr.core.metadata.v3 import ArrayV3Metadata, DataType
from zarr.core.sync import sync
from zarr.errors import ContainsArrayError, ContainsGroupError
from zarr.errors import (
ContainsArrayError,
ContainsGroupError,
ZarrDeprecationWarning,
ZarrFutureWarning,
)
from zarr.storage import LocalStore, MemoryStore, StorePath

if TYPE_CHECKING:
Expand Down Expand Up @@ -229,46 +234,46 @@ def test_array_v3_fill_value(store: MemoryStore, fill_value: int, dtype_str: str


async def test_create_deprecated() -> None:
with pytest.warns(DeprecationWarning):
with pytest.warns(FutureWarning, match=re.escape("Pass shape=(2, 2) as keyword args")):
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(DeprecationWarning):
with pytest.warns(FutureWarning, match=re.escape("Pass shape=(2, 2) as keyword args")):
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(FutureWarning, match="Pass out"):
with pytest.warns(ZarrFutureWarning, match="Pass out"):
arr.get_basic_selection(..., NDBuffer(array=np.empty((2, 2))))

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

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

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

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

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

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

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

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

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


Expand Down
Loading