Skip to content

Commit 79dd9e2

Browse files
committed
define zarr-specific FutureWarning and DeprecationWarning
1 parent f674236 commit 79dd9e2

File tree

15 files changed

+83
-53
lines changed

15 files changed

+83
-53
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ filterwarnings = [
408408
"ignore:Automatic shard shape inference is experimental and may change without notice.*:UserWarning",
409409
"ignore:The codec .* is currently not part in the Zarr format 3 specification.*:UserWarning",
410410
"ignore:The dtype .* is currently not part in the Zarr format 3 specification.*:UserWarning",
411-
"ignore:Use zarr.create_array instead.:DeprecationWarning",
411+
"ignore:Use zarr.create_array instead.:zarr.errors.ZarrDeprecationWarning",
412412
"ignore:Duplicate name.*:UserWarning",
413413
"ignore:The `compressor` argument is deprecated. Use `compressors` instead.:UserWarning",
414414
"ignore:Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations.:UserWarning",

src/zarr/_compat.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from inspect import Parameter, signature
55
from typing import Any, TypeVar
66

7+
from zarr.errors import ZarrFutureWarning
8+
79
T = TypeVar("T")
810

911
# Based off https://github.com/scikit-learn/scikit-learn/blob/e87b32a81c70abed8f2e97483758eb64df8255e9/sklearn/utils/validation.py#L63
@@ -54,7 +56,7 @@ def inner_f(*args: Any, **kwargs: Any) -> T:
5456
f"{version} passing these as positional arguments "
5557
"will result in an error"
5658
),
57-
FutureWarning,
59+
ZarrFutureWarning,
5860
stacklevel=2,
5961
)
6062
kwargs.update(zip(sig.parameters, args, strict=False))

src/zarr/api/asynchronous.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
)
4040
from zarr.core.metadata import ArrayMetadataDict, ArrayV2Metadata, ArrayV3Metadata
4141
from zarr.core.metadata.v2 import _default_compressor, _default_filters
42-
from zarr.errors import NodeTypeValidationError
42+
from zarr.errors import NodeTypeValidationError, ZarrDeprecationWarning
4343
from zarr.storage._common import make_store_path
4444

4545
if TYPE_CHECKING:
@@ -159,7 +159,7 @@ def _handle_zarr_version_or_format(
159159
)
160160
if zarr_version is not None:
161161
warnings.warn(
162-
"zarr_version is deprecated, use zarr_format", DeprecationWarning, stacklevel=2
162+
"zarr_version is deprecated, use zarr_format", ZarrDeprecationWarning, stacklevel=2
163163
)
164164
return zarr_version
165165
return zarr_format
@@ -517,7 +517,7 @@ async def save_group(
517517
await asyncio.gather(*aws)
518518

519519

520-
@deprecated("Use AsyncGroup.tree instead.")
520+
@deprecated("Use AsyncGroup.tree instead.", category=ZarrDeprecationWarning)
521521
async def tree(grp: AsyncGroup, expand: bool | None = None, level: int | None = None) -> Any:
522522
"""Provide a rich display of the hierarchy.
523523

src/zarr/api/synchronous.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from zarr.core.group import Group
1212
from zarr.core.sync import sync
1313
from zarr.core.sync_group import create_hierarchy
14+
from zarr.errors import ZarrDeprecationWarning
1415

1516
if TYPE_CHECKING:
1617
from collections.abc import Iterable
@@ -335,7 +336,7 @@ def save_group(
335336
)
336337

337338

338-
@deprecated("Use Group.tree instead.")
339+
@deprecated("Use Group.tree instead.", category=ZarrDeprecationWarning)
339340
def tree(grp: Group, expand: bool | None = None, level: int | None = None) -> Any:
340341
"""Provide a rich display of the hierarchy.
341342

src/zarr/convenience.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
save_group,
2323
tree,
2424
)
25+
from zarr.errors import ZarrDeprecationWarning
2526

2627
__all__ = [
2728
"consolidate_metadata",
@@ -40,6 +41,6 @@
4041
warnings.warn(
4142
"zarr.convenience is deprecated. "
4243
"Import these functions from the top level zarr. namespace instead.",
43-
DeprecationWarning,
44+
ZarrDeprecationWarning,
4445
stacklevel=2,
4546
)

src/zarr/core/array.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
)
111111
from zarr.core.metadata.v3 import DataType, parse_node_type_array
112112
from zarr.core.sync import sync
113-
from zarr.errors import MetadataValidationError
113+
from zarr.errors import MetadataValidationError, ZarrDeprecationWarning
114114
from zarr.registry import (
115115
_parse_array_array_codec,
116116
_parse_array_bytes_codec,
@@ -394,7 +394,7 @@ async def create(
394394
) -> AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]: ...
395395

396396
@classmethod
397-
@deprecated("Use zarr.api.asynchronous.create_array instead.")
397+
@deprecated("Use zarr.api.asynchronous.create_array instead.", category=ZarrDeprecationWarning)
398398
@_deprecate_positional_args
399399
async def create(
400400
cls,
@@ -1002,7 +1002,7 @@ def serializer(self) -> ArrayBytesCodec | None:
10021002
)
10031003

10041004
@property
1005-
@deprecated("Use AsyncArray.compressors instead.")
1005+
@deprecated("Use AsyncArray.compressors instead.", category=ZarrDeprecationWarning)
10061006
def compressor(self) -> numcodecs.abc.Codec | None:
10071007
"""
10081008
Compressor that is applied to each chunk of the array.
@@ -1727,7 +1727,7 @@ class Array:
17271727
_async_array: AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]
17281728

17291729
@classmethod
1730-
@deprecated("Use zarr.create_array instead.")
1730+
@deprecated("Use zarr.create_array instead.", category=ZarrDeprecationWarning)
17311731
@_deprecate_positional_args
17321732
def create(
17331733
cls,
@@ -2115,7 +2115,7 @@ def serializer(self) -> None | ArrayBytesCodec:
21152115
return self._async_array.serializer
21162116

21172117
@property
2118-
@deprecated("Use Array.compressors instead.")
2118+
@deprecated("Use Array.compressors instead.", category=ZarrDeprecationWarning)
21192119
def compressor(self) -> numcodecs.abc.Codec | None:
21202120
"""
21212121
Compressor that is applied to each chunk of the array.

src/zarr/core/group.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@
5353
from zarr.core.metadata import ArrayV2Metadata, ArrayV3Metadata
5454
from zarr.core.metadata.v3 import V3JsonEncoder, _replace_special_floats
5555
from zarr.core.sync import SyncMixin, sync
56-
from zarr.errors import ContainsArrayError, ContainsGroupError, MetadataValidationError
56+
from zarr.errors import (
57+
ContainsArrayError,
58+
ContainsGroupError,
59+
MetadataValidationError,
60+
ZarrDeprecationWarning,
61+
)
5762
from zarr.storage import StoreLike, StorePath
5863
from zarr.storage._common import ensure_no_existing_node, make_store_path
5964
from zarr.storage._utils import _join_paths, _normalize_path_keys, normalize_path
@@ -1128,7 +1133,7 @@ async def create_array(
11281133
config=config,
11291134
)
11301135

1131-
@deprecated("Use AsyncGroup.create_array instead.")
1136+
@deprecated("Use AsyncGroup.create_array instead.", category=ZarrDeprecationWarning)
11321137
async def create_dataset(
11331138
self, name: str, *, shape: ShapeLike, **kwargs: Any
11341139
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
@@ -1162,7 +1167,7 @@ async def create_dataset(
11621167
await array.setitem(slice(None), data)
11631168
return array
11641169

1165-
@deprecated("Use AsyncGroup.require_array instead.")
1170+
@deprecated("Use AsyncGroup.require_array instead.", category=ZarrDeprecationWarning)
11661171
async def require_dataset(
11671172
self,
11681173
name: str,
@@ -2504,7 +2509,7 @@ def create_array(
25042509
)
25052510
)
25062511

2507-
@deprecated("Use Group.create_array instead.")
2512+
@deprecated("Use Group.create_array instead.", category=ZarrDeprecationWarning)
25082513
def create_dataset(self, name: str, **kwargs: Any) -> Array:
25092514
"""Create an array.
25102515
@@ -2528,7 +2533,7 @@ def create_dataset(self, name: str, **kwargs: Any) -> Array:
25282533
"""
25292534
return Array(self._sync(self._async_group.create_dataset(name, **kwargs)))
25302535

2531-
@deprecated("Use Group.require_array instead.")
2536+
@deprecated("Use Group.require_array instead.", category=ZarrDeprecationWarning)
25322537
def require_dataset(self, name: str, *, shape: ShapeLike, **kwargs: Any) -> Array:
25332538
"""Obtain an array, creating if it doesn't exist.
25342539
@@ -2758,7 +2763,7 @@ def move(self, source: str, dest: str) -> None:
27582763
"""
27592764
return self._sync(self._async_group.move(source, dest))
27602765

2761-
@deprecated("Use Group.create_array instead.")
2766+
@deprecated("Use Group.create_array instead.", category=ZarrDeprecationWarning)
27622767
@_deprecate_positional_args
27632768
def array(
27642769
self,

src/zarr/creation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
zeros,
2424
zeros_like,
2525
)
26+
from zarr.errors import ZarrDeprecationWarning
2627

2728
__all__ = [
2829
"array",
@@ -42,6 +43,6 @@
4243
warnings.warn(
4344
"zarr.creation is deprecated. "
4445
"Import these functions from the top level zarr. namespace instead.",
45-
DeprecationWarning,
46+
ZarrDeprecationWarning,
4647
stacklevel=2,
4748
)

src/zarr/errors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ class NodeTypeValidationError(MetadataValidationError):
5757
This can be raised when the value is invalid or unexpected given the context,
5858
for example an 'array' node when we expected a 'group'.
5959
"""
60+
61+
62+
class ZarrFutureWarning(FutureWarning): ...
63+
64+
65+
class ZarrDeprecationWarning(DeprecationWarning): ...

src/zarr/storage/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from types import ModuleType
44
from typing import Any
55

6+
from zarr.errors import ZarrDeprecationWarning
67
from zarr.storage._common import StoreLike, StorePath
78
from zarr.storage._fsspec import FsspecStore
89
from zarr.storage._local import LocalStore
@@ -33,7 +34,7 @@ def __setattr__(self, attr: str, value: Any) -> None:
3334
"setting zarr.storage.default_compressor is deprecated, use "
3435
"zarr.config to configure array.v2_default_compressor "
3536
"e.g. config.set({'codecs.zstd':'numcodecs.Zstd', 'array.v2_default_compressor.numeric': 'zstd'})",
36-
DeprecationWarning,
37+
ZarrDeprecationWarning,
3738
stacklevel=1,
3839
)
3940
else:

0 commit comments

Comments
 (0)