Skip to content

Commit 9055d3b

Browse files
committed
handle warnings in tests explicitly; make userwarnings ZarrUserWarning
1 parent 917fd3d commit 9055d3b

File tree

22 files changed

+348
-190
lines changed

22 files changed

+348
-190
lines changed

pyproject.toml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,6 @@ addopts = [
403403
]
404404
filterwarnings = [
405405
"error",
406-
# TODO: explicitly filter or catch the warnings below where we expect them to be emitted in the tests
407-
"ignore:Consolidated metadata is currently not part in the Zarr format 3 specification.*:UserWarning",
408-
"ignore:Creating a zarr.buffer.gpu.Buffer with an array that does not support the __cuda_array_interface__.*:UserWarning",
409-
"ignore:Automatic shard shape inference is experimental and may change without notice.*:UserWarning",
410-
"ignore:The codec .* is currently not part in the Zarr format 3 specification.*:UserWarning",
411-
"ignore:The dtype .* is currently not part in the Zarr format 3 specification.*:UserWarning",
412-
"ignore:Use zarr.create_array instead.:zarr.errors.ZarrDeprecationWarning",
413-
"ignore:Duplicate name.*:UserWarning",
414-
"ignore:The `compressor` argument is deprecated. Use `compressors` instead.:UserWarning",
415-
"ignore:Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations.:UserWarning",
416406
"ignore:Unclosed client session <aiohttp.client.ClientSession.*:ResourceWarning"
417407
]
418408
markers = [

src/zarr/api/asynchronous.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@
3939
create_hierarchy,
4040
)
4141
from zarr.core.metadata import ArrayMetadataDict, ArrayV2Metadata, ArrayV3Metadata
42-
from zarr.errors import GroupNotFoundError, NodeTypeValidationError, ZarrDeprecationWarning
42+
from zarr.errors import (
43+
GroupNotFoundError,
44+
NodeTypeValidationError,
45+
ZarrDeprecationWarning,
46+
ZarrRuntimeWarning,
47+
ZarrUserWarning,
48+
)
4349
from zarr.storage import StorePath
4450
from zarr.storage._common import make_store_path
4551

@@ -228,7 +234,7 @@ async def consolidate_metadata(
228234
warnings.warn(
229235
"Consolidated metadata is currently not part in the Zarr format 3 specification. It "
230236
"may not be supported by other zarr implementations and may change in the future.",
231-
category=UserWarning,
237+
category=ZarrUserWarning,
232238
stacklevel=1,
233239
)
234240

@@ -674,13 +680,13 @@ async def group(
674680
store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options)
675681

676682
if chunk_store is not None:
677-
warnings.warn("chunk_store is not yet implemented", RuntimeWarning, stacklevel=2)
683+
warnings.warn("chunk_store is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
678684
if cache_attrs is not None:
679-
warnings.warn("cache_attrs is not yet implemented", RuntimeWarning, stacklevel=2)
685+
warnings.warn("cache_attrs is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
680686
if synchronizer is not None:
681-
warnings.warn("synchronizer is not yet implemented", RuntimeWarning, stacklevel=2)
687+
warnings.warn("synchronizer is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
682688
if meta_array is not None:
683-
warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2)
689+
warnings.warn("meta_array is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
684690

685691
if attributes is None:
686692
attributes = {}
@@ -827,13 +833,13 @@ async def open_group(
827833
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
828834

829835
if cache_attrs is not None:
830-
warnings.warn("cache_attrs is not yet implemented", RuntimeWarning, stacklevel=2)
836+
warnings.warn("cache_attrs is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
831837
if synchronizer is not None:
832-
warnings.warn("synchronizer is not yet implemented", RuntimeWarning, stacklevel=2)
838+
warnings.warn("synchronizer is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
833839
if meta_array is not None:
834-
warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2)
840+
warnings.warn("meta_array is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
835841
if chunk_store is not None:
836-
warnings.warn("chunk_store is not yet implemented", RuntimeWarning, stacklevel=2)
842+
warnings.warn("chunk_store is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
837843

838844
store_path = await make_store_path(store, mode=mode, storage_options=storage_options, path=path)
839845
if attributes is None:
@@ -1011,19 +1017,19 @@ async def create(
10111017
)
10121018

10131019
if synchronizer is not None:
1014-
warnings.warn("synchronizer is not yet implemented", RuntimeWarning, stacklevel=2)
1020+
warnings.warn("synchronizer is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
10151021
if chunk_store is not None:
1016-
warnings.warn("chunk_store is not yet implemented", RuntimeWarning, stacklevel=2)
1022+
warnings.warn("chunk_store is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
10171023
if cache_metadata is not None:
1018-
warnings.warn("cache_metadata is not yet implemented", RuntimeWarning, stacklevel=2)
1024+
warnings.warn("cache_metadata is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
10191025
if cache_attrs is not None:
1020-
warnings.warn("cache_attrs is not yet implemented", RuntimeWarning, stacklevel=2)
1026+
warnings.warn("cache_attrs is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
10211027
if object_codec is not None:
1022-
warnings.warn("object_codec is not yet implemented", RuntimeWarning, stacklevel=2)
1028+
warnings.warn("object_codec is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
10231029
if read_only is not None:
1024-
warnings.warn("read_only is not yet implemented", RuntimeWarning, stacklevel=2)
1030+
warnings.warn("read_only is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
10251031
if meta_array is not None:
1026-
warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2)
1032+
warnings.warn("meta_array is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
10271033

10281034
if write_empty_chunks is not None:
10291035
_warn_write_empty_chunks_kwarg()
@@ -1042,7 +1048,7 @@ async def create(
10421048
"This is redundant. When both are set, write_empty_chunks will be used instead "
10431049
"of the value in config."
10441050
)
1045-
warnings.warn(UserWarning(msg), stacklevel=1)
1051+
warnings.warn(ZarrUserWarning(msg), stacklevel=1)
10461052
config_parsed = dataclasses.replace(config_parsed, write_empty_chunks=write_empty_chunks)
10471053

10481054
return await AsyncArray._create(

src/zarr/core/array.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
)
120120
from zarr.core.metadata.v3 import parse_node_type_array
121121
from zarr.core.sync import sync
122-
from zarr.errors import MetadataValidationError, ZarrDeprecationWarning
122+
from zarr.errors import MetadataValidationError, ZarrDeprecationWarning, ZarrUserWarning
123123
from zarr.registry import (
124124
_parse_array_array_codec,
125125
_parse_array_bytes_codec,
@@ -232,7 +232,7 @@ async def get_array_metadata(
232232
if zarr_json_bytes is not None and zarray_bytes is not None:
233233
# warn and favor v3
234234
msg = f"Both zarr.json (Zarr format 3) and .zarray (Zarr format 2) metadata objects exist at {store_path}. Zarr v3 will be used."
235-
warnings.warn(msg, stacklevel=1)
235+
warnings.warn(msg, category=ZarrUserWarning, stacklevel=1)
236236
if zarr_json_bytes is None and zarray_bytes is None:
237237
raise FileNotFoundError(store_path)
238238
# set zarr_format based on which keys were found
@@ -4648,7 +4648,7 @@ def _parse_keep_array_attr(
46484648
warnings.warn(
46494649
"The 'order' attribute of a Zarr format 2 array does not have a direct analogue in Zarr format 3. "
46504650
"The existing order='F' of the source Zarr format 2 array will be ignored.",
4651-
UserWarning,
4651+
ZarrUserWarning,
46524652
stacklevel=2,
46534653
)
46544654
elif order is None and zarr_format == 2:
@@ -4937,7 +4937,7 @@ def _parse_deprecated_compressor(
49374937
if zarr_format == 3:
49384938
warn(
49394939
"The `compressor` argument is deprecated. Use `compressors` instead.",
4940-
category=UserWarning,
4940+
category=ZarrUserWarning,
49414941
stacklevel=2,
49424942
)
49434943
if compressor is None:

src/zarr/core/buffer/gpu.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from zarr.core.buffer import core
1515
from zarr.core.buffer.core import ArrayLike, BufferPrototype, NDArrayLike
16+
from zarr.errors import ZarrUserWarning
1617
from zarr.registry import (
1718
register_buffer,
1819
register_ndbuffer,
@@ -72,6 +73,7 @@ def __init__(self, array_like: ArrayLike) -> None:
7273
)
7374
warnings.warn(
7475
msg,
76+
category=ZarrUserWarning,
7577
stacklevel=2,
7678
)
7779
self._data = cp.asarray(array_like)

src/zarr/core/chunk_grids.py

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

2627
if TYPE_CHECKING:
2728
from collections.abc import Iterator
@@ -233,7 +234,7 @@ def _auto_partition(
233234
if shard_shape == "auto":
234235
warnings.warn(
235236
"Automatic shard shape inference is experimental and may change without notice.",
236-
UserWarning,
237+
ZarrUserWarning,
237238
stacklevel=2,
238239
)
239240
_shards_out = ()

src/zarr/core/codec_pipeline.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from zarr.core.common import ChunkCoords, concurrent_map
1818
from zarr.core.config import config
1919
from zarr.core.indexing import SelectorTuple, is_scalar
20+
from zarr.errors import ZarrUserWarning
2021
from zarr.registry import register_pipeline
2122

2223
if TYPE_CHECKING:
@@ -501,6 +502,7 @@ def codecs_from_list(
501502
warn(
502503
"Combining a `sharding_indexed` codec disables partial reads and "
503504
"writes, which may lead to inefficient performance.",
505+
category=ZarrUserWarning,
504506
stacklevel=3,
505507
)
506508

src/zarr/core/common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from typing_extensions import ReadOnly
2424

2525
from zarr.core.config import config as zarr_config
26+
from zarr.errors import ZarrRuntimeWarning
2627

2728
if TYPE_CHECKING:
2829
from collections.abc import Awaitable, Callable, Iterator
@@ -205,7 +206,7 @@ def _warn_write_empty_chunks_kwarg() -> None:
205206
"argument, as in `config={'write_empty_chunks': True}`,"
206207
"or change the global 'array.write_empty_chunks' configuration variable."
207208
)
208-
warnings.warn(msg, RuntimeWarning, stacklevel=2)
209+
warnings.warn(msg, ZarrRuntimeWarning, stacklevel=2)
209210

210211

211212
def _warn_order_kwarg() -> None:
@@ -216,7 +217,7 @@ def _warn_order_kwarg() -> None:
216217
"argument, as in `config={'order': 'C'}`,"
217218
"or change the global 'array.order' configuration variable."
218219
)
219-
warnings.warn(msg, RuntimeWarning, stacklevel=2)
220+
warnings.warn(msg, ZarrRuntimeWarning, stacklevel=2)
220221

221222

222223
def _default_zarr_format() -> ZarrFormat:

src/zarr/core/group.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
ContainsGroupError,
5656
MetadataValidationError,
5757
ZarrDeprecationWarning,
58+
ZarrUserWarning,
5859
)
5960
from zarr.storage import StoreLike, StorePath
6061
from zarr.storage._common import ensure_no_existing_node, make_store_path
@@ -553,7 +554,7 @@ async def open(
553554
if zarr_json_bytes is not None and zgroup_bytes is not None:
554555
# warn and favor v3
555556
msg = f"Both zarr.json (Zarr format 3) and .zgroup (Zarr format 2) metadata objects exist at {store_path}. Zarr format 3 will be used."
556-
warnings.warn(msg, stacklevel=1)
557+
warnings.warn(msg, category=ZarrUserWarning, stacklevel=1)
557558
if zarr_json_bytes is None and zgroup_bytes is None:
558559
raise FileNotFoundError(
559560
f"could not find zarr.json or .zgroup objects in {store_path}"
@@ -3380,7 +3381,7 @@ async def _iter_members(
33803381
# in which case `key` cannot be the name of a sub-array or sub-group.
33813382
warnings.warn(
33823383
f"Object at {e.args[0]} is not recognized as a component of a Zarr hierarchy.",
3383-
UserWarning,
3384+
ZarrUserWarning,
33843385
stacklevel=1,
33853386
)
33863387
continue

src/zarr/core/metadata/v2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from zarr.core.chunk_grids import RegularChunkGrid
1212
from zarr.core.dtype import get_data_type_from_json
1313
from zarr.core.dtype.common import OBJECT_CODEC_IDS, DTypeSpec_V2
14+
from zarr.errors import ZarrUserWarning
1415

1516
if TYPE_CHECKING:
1617
from typing import Literal, Self
@@ -188,7 +189,7 @@ def from_dict(cls, data: dict[str, Any]) -> ArrayV2Metadata:
188189
"This is contrary to the Zarr V2 specification, and will cause an error in the future. "
189190
"Use None (or Null in a JSON document) instead of an empty list of filters."
190191
)
191-
warnings.warn(msg, UserWarning, stacklevel=1)
192+
warnings.warn(msg, ZarrUserWarning, stacklevel=1)
192193
_data["filters"] = None
193194

194195
_data = {k: v for k, v in _data.items() if k in expected}

src/zarr/errors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,15 @@ class ZarrDeprecationWarning(DeprecationWarning):
8080
"""
8181
A warning raised to indicate that a construct will be removed in a future release.
8282
"""
83+
84+
85+
class ZarrUserWarning(UserWarning):
86+
"""
87+
A warning raised to report problems with user code.
88+
"""
89+
90+
91+
class ZarrRuntimeWarning(RuntimeWarning):
92+
"""
93+
A warning for dubious runtime behavior.
94+
"""

0 commit comments

Comments
 (0)