99from zarr .attrs import Attributes
1010from zarr .core import Array
1111from zarr .storage import contains_array , contains_group , init_group , \
12- DictStore , DirectoryStore , group_meta_key , attrs_key , listdir , rmdir
12+ DictStore , DirectoryStore , group_meta_key , attrs_key , listdir
1313from zarr .creation import array , create , empty , zeros , ones , full , \
1414 empty_like , zeros_like , ones_like , full_like
1515from zarr .util import normalize_storage_path , normalize_shape
16- from zarr .errors import PermissionError
16+ from zarr .errors import PermissionError , err_contains_array , \
17+ err_contains_group , err_group_not_found , err_read_only
1718from zarr .meta import decode_group_metadata
1819
1920
@@ -91,14 +92,14 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
9192
9293 # guard conditions
9394 if contains_array (store , path = self ._path ):
94- raise ValueError ( 'store contains an array' )
95+ err_contains_array ( path )
9596
9697 # initialize metadata
9798 try :
9899 mkey = self ._key_prefix + group_meta_key
99100 meta_bytes = store [mkey ]
100101 except KeyError :
101- raise ValueError ( 'store has no metadata' )
102+ err_group_not_found ( path )
102103 else :
103104 meta = decode_group_metadata (meta_bytes )
104105 self ._meta = meta
@@ -285,7 +286,7 @@ def __getitem__(self, item):
285286 store: DictStore
286287 >>> g1['foo/bar/baz']
287288 Array(/foo/bar/baz, (100,), float64, chunks=(10,), order=C)
288- nbytes: 800; nbytes_stored: 293 ; ratio: 2.7 ; initialized: 0/10
289+ nbytes: 800; nbytes_stored: 290 ; ratio: 2.8 ; initialized: 0/10
289290 compressor: Blosc(cname='lz4', clevel=5, shuffle=1)
290291 store: DictStore
291292
@@ -396,7 +397,7 @@ def _write_op(self, f, *args, **kwargs):
396397
397398 # guard condition
398399 if self ._read_only :
399- raise PermissionError ( 'group is read-only' )
400+ err_read_only ( )
400401
401402 # synchronization
402403 if self ._synchronizer is None :
@@ -494,7 +495,7 @@ def require_groups(self, *names):
494495 return tuple (self .require_group (name ) for name in names )
495496
496497 def create_dataset (self , name , data = None , shape = None , chunks = None ,
497- dtype = None , compressor = 'default' , fill_value = None ,
498+ dtype = None , compressor = 'default' , fill_value = 0 ,
498499 order = 'C' , synchronizer = None , filters = None ,
499500 overwrite = False , cache_metadata = True , ** kwargs ):
500501 """Create an array.
@@ -543,7 +544,7 @@ def create_dataset(self, name, data=None, shape=None, chunks=None,
543544 ... chunks=(1000, 1000))
544545 >>> d1
545546 Array(/foo, (10000, 10000), float64, chunks=(1000, 1000), order=C)
546- nbytes: 762.9M; nbytes_stored: 326 ; ratio: 2453987.7 ; initialized: 0/100
547+ nbytes: 762.9M; nbytes_stored: 323 ; ratio: 2476780.2 ; initialized: 0/100
547548 compressor: Blosc(cname='lz4', clevel=5, shuffle=1)
548549 store: DictStore
549550
@@ -558,7 +559,7 @@ def create_dataset(self, name, data=None, shape=None, chunks=None,
558559
559560 def _create_dataset_nosync (self , name , data = None , shape = None , chunks = None ,
560561 dtype = None , compressor = 'default' ,
561- fill_value = None , order = 'C' , synchronizer = None ,
562+ fill_value = 0 , order = 'C' , synchronizer = None ,
562563 filters = None , overwrite = False ,
563564 cache_metadata = True , ** kwargs ):
564565
@@ -804,6 +805,7 @@ def group(store=None, overwrite=False, chunk_store=None, synchronizer=None,
804805
805806 # handle polymorphic store arg
806807 store = _handle_store_arg (store )
808+ path = normalize_storage_path (path )
807809
808810 # require group
809811 if overwrite or not contains_group (store ):
@@ -857,29 +859,30 @@ def open_group(store=None, mode='a', synchronizer=None, path=None):
857859
858860 # handle polymorphic store arg
859861 store = _handle_store_arg (store )
862+ path = normalize_storage_path (path )
860863
861864 # ensure store is initialized
862865
863866 if mode in ['r' , 'r+' ]:
864867 if contains_array (store , path = path ):
865- raise ValueError ( 'store contains array' )
868+ err_contains_array ( path )
866869 elif not contains_group (store , path = path ):
867- raise ValueError ( 'group does not exist' )
870+ err_group_not_found ( path )
868871
869872 elif mode == 'w' :
870873 init_group (store , overwrite = True , path = path )
871874
872875 elif mode == 'a' :
873876 if contains_array (store , path = path ):
874- raise ValueError ( 'store contains array' )
877+ err_contains_array ( path )
875878 if not contains_group (store , path = path ):
876879 init_group (store , path = path )
877880
878881 elif mode in ['w-' , 'x' ]:
879882 if contains_array (store , path = path ):
880- raise ValueError ( 'store contains array' )
883+ err_contains_array ( path )
881884 elif contains_group (store , path = path ):
882- raise ValueError ( 'store contains group' )
885+ err_contains_group ( path )
883886 else :
884887 init_group (store , path = path )
885888
0 commit comments