77import numpy as np
88
99
10- from zarr .attrs import Attributes
10+ from zarr .attrs import Attributes , SynchronizedAttributes
1111from zarr .core import Array
1212from zarr .storage import contains_array , contains_group , init_group , \
1313 DictStore , DirectoryStore , group_meta_key , attrs_key , listdir
@@ -526,14 +526,6 @@ def create_dataset(self, name, data=None, shape=None, chunks=None,
526526 # setup
527527 if self ._readonly :
528528 raise ReadOnlyError ('group is read-only' )
529- path = self ._item_path (name )
530- self ._require_parent_group (path )
531-
532- # guard conditions
533- if contains_array (self ._store , path ):
534- raise KeyError (name )
535- if contains_group (self ._store , path ):
536- raise KeyError (name )
537529
538530 # N.B., additional kwargs are included in method signature to
539531 # improve compatibility for users familiar with h5py and adapting
@@ -546,6 +538,26 @@ def create_dataset(self, name, data=None, shape=None, chunks=None,
546538 else :
547539 warn ('ignoring keyword argument %r' % k )
548540
541+ self ._create_dataset (name , data = data , shape = shape , chunks = chunks ,
542+ dtype = dtype , compression = compression ,
543+ compression_opts = compression_opts ,
544+ fill_value = fill_value , order = order ,
545+ synchronizer = synchronizer )
546+
547+ def _create_dataset (self , name , data = None , shape = None , chunks = None ,
548+ dtype = None , compression = 'default' ,
549+ compression_opts = None , fill_value = None , order = 'C' ,
550+ synchronizer = None ):
551+
552+ path = self ._item_path (name )
553+ self ._require_parent_group (path )
554+
555+ # guard conditions
556+ if contains_array (self ._store , path ):
557+ raise KeyError (name )
558+ if contains_group (self ._store , path ):
559+ raise KeyError (name )
560+
549561 if data is not None :
550562 a = array (data , chunks = chunks , dtype = dtype ,
551563 compression = compression ,
@@ -600,8 +612,10 @@ def require_dataset(self, name, shape, dtype=None, exact=False, **kwargs):
600612 return a
601613
602614 else :
603- return self .create_dataset (name , shape = shape , dtype = dtype ,
604- ** kwargs )
615+ if self ._readonly :
616+ raise ReadOnlyError ('group is read-only' )
617+ return self ._create_dataset (name , shape = shape , dtype = dtype ,
618+ ** kwargs )
605619
606620 def create (self , name , ** kwargs ):
607621 """Create an array. Keyword arguments as per
@@ -830,3 +844,35 @@ def open_group(path, mode='a'):
830844 readonly = mode == 'r'
831845
832846 return Group (store , readonly = readonly )
847+
848+
849+ class SynchronizedGroup (Group ):
850+ """TODO doc me"""
851+
852+ def __init__ (self , store , synchronizer , path = None , readonly = False ,
853+ chunk_store = None ):
854+ super (SynchronizedGroup , self ).__init__ (store , path = path ,
855+ readonly = readonly ,
856+ chunk_store = chunk_store )
857+ self ._synchronizer = synchronizer
858+ akey = self ._key_prefix + attrs_key
859+ self ._attrs = SynchronizedAttributes (store , synchronizer , key = akey ,
860+ readonly = readonly )
861+
862+ def __repr__ (self ):
863+ r = super (SynchronizedGroup , self ).__repr__ ()
864+ r += ('\n synchronizer: %s.%s' %
865+ (type (self ._synchronizer ).__module__ ,
866+ type (self ._synchronizer ).__name__ ))
867+ return r
868+
869+ def __getstate__ (self ):
870+ return self ._store , self ._synchronizer , self ._path , self ._readonly , \
871+ self ._chunk_store
872+
873+ def __setstate__ (self , state ):
874+ self .__init__ (* state )
875+
876+ def __getitem__ (self , item ):
877+ # TODO
878+ pass
0 commit comments