File tree Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1414from zarr .core .group import AsyncGroup
1515from zarr .core .metadata .v2 import ArrayV2Metadata
1616from zarr .core .metadata .v3 import ArrayV3Metadata
17+ from zarr .errors import NodeTypeValidationError
1718from zarr .storage import (
1819 StoreLike ,
1920 StorePath ,
@@ -247,9 +248,9 @@ async def open(
247248
248249 try :
249250 return await open_array (store = store_path , zarr_format = zarr_format , ** kwargs )
250- except (KeyError , ValueError ):
251+ except (KeyError , NodeTypeValidationError ):
251252 # KeyError for a missing key
252- # ValueError for failing to parse node metadata as an array when it's
253+ # NodeTypeValidationError for failing to parse node metadata as an array when it's
253254 # actually a group
254255 return await open_group (store = store_path , zarr_format = zarr_format , ** kwargs )
255256
Original file line number Diff line number Diff line change 2828from zarr .core .common import ZARR_JSON , parse_named_configuration , parse_shapelike
2929from zarr .core .config import config
3030from zarr .core .metadata .common import ArrayMetadata , parse_attributes
31+ from zarr .errors import MetadataValidationError , NodeTypeValidationError
3132from zarr .registry import get_codec_class
3233
3334DEFAULT_DTYPE = "float64"
3637def parse_zarr_format (data : object ) -> Literal [3 ]:
3738 if data == 3 :
3839 return 3
39- raise ValueError (f"Invalid value. Expected 3. Got { data } ." )
40+ raise MetadataValidationError (f"Invalid value. Expected 3. Got { data } ." )
4041
4142
4243def parse_node_type_array (data : object ) -> Literal ["array" ]:
4344 if data == "array" :
4445 return "array"
45- raise ValueError (f"Invalid value. Expected 'array'. Got { data } ." )
46+ raise NodeTypeValidationError (f"Invalid value. Expected 'array'. Got { data } ." )
4647
4748
4849def parse_codecs (data : object ) -> tuple [Codec , ...]:
Original file line number Diff line number Diff line change @@ -25,6 +25,19 @@ class ContainsArrayAndGroupError(_BaseZarrError):
2525 )
2626
2727
28+ class MetadataValidationError (_BaseZarrError ):
29+ """An exception raised when the Zarr metadata is invalid in some way"""
30+
31+
32+ class NodeTypeValidationError (MetadataValidationError ):
33+ """
34+ Specialized exception when the node_type of the metadata document is incorrect..
35+
36+ This can be raised when the value is invalid or unexpected given the context,
37+ for example an 'array' node when we expected a 'group'.
38+ """
39+
40+
2841__all__ = [
2942 "ContainsArrayAndGroupError" ,
3043 "ContainsArrayError" ,
You can’t perform that action at this time.
0 commit comments