@@ -712,13 +712,13 @@ _repr_shuffle = [
712
712
cdef class BaseArray:
713
713
714
714
def __cinit__ (self , shape = None , chunks = None , dtype = None , cname = None ,
715
- clevel = None , shuffle = None , fill_value = None , **kwargs ):
715
+ clevel = None , shuffle = None , fill_value = 0 , **kwargs ):
716
716
717
717
# N.B., the convention in h5py and dask is to use the "chunks"
718
718
# argument as a tuple representing the shape of each chunk,
719
719
# so we follow that convention here.
720
720
721
- # delegate entirely to sub-classes
721
+ # delegate attribute setting entirely to sub-classes
722
722
pass
723
723
724
724
property shape :
@@ -1130,6 +1130,9 @@ cdef class PersistentArray(BaseArray):
1130
1130
# w- or x : create, fail if exists
1131
1131
# a : read/write if exists, create otherwise (default)
1132
1132
1133
+ # use metadata file as indicator of array existence
1134
+ meta_path = os.path.join(path, defaults.metapath)
1135
+
1133
1136
if mode in [' r' , ' r+' ]:
1134
1137
self ._open(path)
1135
1138
@@ -1139,12 +1142,12 @@ cdef class PersistentArray(BaseArray):
1139
1142
self ._create(path, ** kwargs)
1140
1143
1141
1144
elif mode in [' w-' , ' x' ]:
1142
- if os.path.exists(path ):
1143
- raise ValueError (' path exists: %s ' % path)
1145
+ if os.path.exists(meta_path ):
1146
+ raise ValueError (' array exists: %s ' % path)
1144
1147
self ._create(path, ** kwargs)
1145
1148
1146
1149
elif mode == ' a' :
1147
- if os.path.exists(path ):
1150
+ if os.path.exists(meta_path ):
1148
1151
self ._open(path)
1149
1152
else :
1150
1153
self ._create(path, ** kwargs)
@@ -1170,8 +1173,10 @@ cdef class PersistentArray(BaseArray):
1170
1173
def _create (self , path , shape = None , chunks = None , dtype = None ,
1171
1174
cname = None , clevel = None , shuffle = None , fill_value = None ):
1172
1175
1173
- # create directory
1174
- os.makedirs(os.path.join(path, defaults.datapath))
1176
+ # create directories
1177
+ data_path = os.path.join(path, defaults.datapath)
1178
+ if not os.path.exists(data_path):
1179
+ os.makedirs(data_path)
1175
1180
1176
1181
# set attributes
1177
1182
self ._shape = normalize_shape(shape)
0 commit comments