Skip to content

Commit 64621d5

Browse files
committed
refactor array tests
1 parent 2e3b898 commit 64621d5

File tree

5 files changed

+390
-511
lines changed

5 files changed

+390
-511
lines changed

zarr/ext.pyx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -712,13 +712,13 @@ _repr_shuffle = [
712712
cdef class BaseArray:
713713

714714
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):
716716

717717
# N.B., the convention in h5py and dask is to use the "chunks"
718718
# argument as a tuple representing the shape of each chunk,
719719
# so we follow that convention here.
720720

721-
# delegate entirely to sub-classes
721+
# delegate attribute setting entirely to sub-classes
722722
pass
723723

724724
property shape:
@@ -1130,6 +1130,9 @@ cdef class PersistentArray(BaseArray):
11301130
# w- or x : create, fail if exists
11311131
# a : read/write if exists, create otherwise (default)
11321132

1133+
# use metadata file as indicator of array existence
1134+
meta_path = os.path.join(path, defaults.metapath)
1135+
11331136
if mode in ['r', 'r+']:
11341137
self._open(path)
11351138

@@ -1139,12 +1142,12 @@ cdef class PersistentArray(BaseArray):
11391142
self._create(path, **kwargs)
11401143

11411144
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)
11441147
self._create(path, **kwargs)
11451148

11461149
elif mode == 'a':
1147-
if os.path.exists(path):
1150+
if os.path.exists(meta_path):
11481151
self._open(path)
11491152
else:
11501153
self._create(path, **kwargs)
@@ -1170,8 +1173,10 @@ cdef class PersistentArray(BaseArray):
11701173
def _create(self, path, shape=None, chunks=None, dtype=None,
11711174
cname=None, clevel=None, shuffle=None, fill_value=None):
11721175

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)
11751180

11761181
# set attributes
11771182
self._shape = normalize_shape(shape)

0 commit comments

Comments
 (0)