9
9
from zarr .attrs import Attributes
10
10
from zarr .core import Array
11
11
from 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
13
13
from zarr .creation import array , create , empty , zeros , ones , full , \
14
14
empty_like , zeros_like , ones_like , full_like
15
15
from 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
17
18
from zarr .meta import decode_group_metadata
18
19
19
20
@@ -91,14 +92,14 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
91
92
92
93
# guard conditions
93
94
if contains_array (store , path = self ._path ):
94
- raise ValueError ( 'store contains an array' )
95
+ err_contains_array ( path )
95
96
96
97
# initialize metadata
97
98
try :
98
99
mkey = self ._key_prefix + group_meta_key
99
100
meta_bytes = store [mkey ]
100
101
except KeyError :
101
- raise ValueError ( 'store has no metadata' )
102
+ err_group_not_found ( path )
102
103
else :
103
104
meta = decode_group_metadata (meta_bytes )
104
105
self ._meta = meta
@@ -285,7 +286,7 @@ def __getitem__(self, item):
285
286
store: DictStore
286
287
>>> g1['foo/bar/baz']
287
288
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
289
290
compressor: Blosc(cname='lz4', clevel=5, shuffle=1)
290
291
store: DictStore
291
292
@@ -396,7 +397,7 @@ def _write_op(self, f, *args, **kwargs):
396
397
397
398
# guard condition
398
399
if self ._read_only :
399
- raise PermissionError ( 'group is read-only' )
400
+ err_read_only ( )
400
401
401
402
# synchronization
402
403
if self ._synchronizer is None :
@@ -494,7 +495,7 @@ def require_groups(self, *names):
494
495
return tuple (self .require_group (name ) for name in names )
495
496
496
497
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 ,
498
499
order = 'C' , synchronizer = None , filters = None ,
499
500
overwrite = False , cache_metadata = True , ** kwargs ):
500
501
"""Create an array.
@@ -543,7 +544,7 @@ def create_dataset(self, name, data=None, shape=None, chunks=None,
543
544
... chunks=(1000, 1000))
544
545
>>> d1
545
546
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
547
548
compressor: Blosc(cname='lz4', clevel=5, shuffle=1)
548
549
store: DictStore
549
550
@@ -558,7 +559,7 @@ def create_dataset(self, name, data=None, shape=None, chunks=None,
558
559
559
560
def _create_dataset_nosync (self , name , data = None , shape = None , chunks = None ,
560
561
dtype = None , compressor = 'default' ,
561
- fill_value = None , order = 'C' , synchronizer = None ,
562
+ fill_value = 0 , order = 'C' , synchronizer = None ,
562
563
filters = None , overwrite = False ,
563
564
cache_metadata = True , ** kwargs ):
564
565
@@ -804,6 +805,7 @@ def group(store=None, overwrite=False, chunk_store=None, synchronizer=None,
804
805
805
806
# handle polymorphic store arg
806
807
store = _handle_store_arg (store )
808
+ path = normalize_storage_path (path )
807
809
808
810
# require group
809
811
if overwrite or not contains_group (store ):
@@ -857,29 +859,30 @@ def open_group(store=None, mode='a', synchronizer=None, path=None):
857
859
858
860
# handle polymorphic store arg
859
861
store = _handle_store_arg (store )
862
+ path = normalize_storage_path (path )
860
863
861
864
# ensure store is initialized
862
865
863
866
if mode in ['r' , 'r+' ]:
864
867
if contains_array (store , path = path ):
865
- raise ValueError ( 'store contains array' )
868
+ err_contains_array ( path )
866
869
elif not contains_group (store , path = path ):
867
- raise ValueError ( 'group does not exist' )
870
+ err_group_not_found ( path )
868
871
869
872
elif mode == 'w' :
870
873
init_group (store , overwrite = True , path = path )
871
874
872
875
elif mode == 'a' :
873
876
if contains_array (store , path = path ):
874
- raise ValueError ( 'store contains array' )
877
+ err_contains_array ( path )
875
878
if not contains_group (store , path = path ):
876
879
init_group (store , path = path )
877
880
878
881
elif mode in ['w-' , 'x' ]:
879
882
if contains_array (store , path = path ):
880
- raise ValueError ( 'store contains array' )
883
+ err_contains_array ( path )
881
884
elif contains_group (store , path = path ):
882
- raise ValueError ( 'store contains group' )
885
+ err_contains_group ( path )
883
886
else :
884
887
init_group (store , path = path )
885
888
0 commit comments