Skip to content

Commit 1a8c55c

Browse files
committed
nchunks; resolves #51
1 parent bde89ae commit 1a8c55c

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

zarr/core.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ class Array(object):
6161
itemsize
6262
nbytes
6363
nbytes_stored
64-
initialized
6564
cdata_shape
65+
nchunks
66+
nchunks_initialized
6667
is_view
6768
6869
Methods
@@ -263,12 +264,6 @@ def nbytes_stored(self):
263264
else:
264265
return m + n
265266

266-
@property
267-
def initialized(self):
268-
"""The number of chunks that have been initialized with some data."""
269-
return sum(1 for k in listdir(self._chunk_store, self._path)
270-
if k not in [array_meta_key, attrs_key])
271-
272267
@property
273268
def cdata_shape(self):
274269
"""A tuple of integers describing the number of chunks along each
@@ -277,6 +272,20 @@ def cdata_shape(self):
277272
int(np.ceil(s / c)) for s, c in zip(self._shape, self._chunks)
278273
)
279274

275+
@property
276+
def nchunks(self):
277+
"""Total number of chunks."""
278+
return reduce(operator.mul, self.cdata_shape)
279+
280+
@property
281+
def nchunks_initialized(self):
282+
"""The number of chunks that have been initialized with some data."""
283+
return sum(1 for k in listdir(self._chunk_store, self._path)
284+
if k not in [array_meta_key, attrs_key])
285+
286+
# backwards compability
287+
initialized = nchunks_initialized
288+
280289
@property
281290
def is_view(self):
282291
"""A boolean, True if this array is a view on another array."""
@@ -755,8 +764,8 @@ def __repr__(self):
755764
r += '; nbytes_stored: %s' % human_readable_size(
756765
self.nbytes_stored)
757766
r += '; ratio: %.1f' % (self.nbytes / self.nbytes_stored)
758-
n_chunks = reduce(operator.mul, self.cdata_shape)
759-
r += '; initialized: %s/%s' % (self.initialized, n_chunks)
767+
r += '; initialized: %s/%s' % (self.nchunks_initialized,
768+
self.nchunks)
760769

761770
# filters
762771
if self.filters:

zarr/tests/test_core.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def test_array_1d(self):
9090
eq(a.dtype, z.dtype)
9191
eq((100,), z.chunks)
9292
eq(a.nbytes, z.nbytes)
93-
eq(0, z.initialized)
93+
eq(11, z.nchunks)
94+
eq(0, z.nchunks_initialized)
9495
eq((11,), z.cdata_shape)
9596

9697
# check empty
@@ -108,7 +109,8 @@ def test_array_1d(self):
108109

109110
# check properties
110111
eq(a.nbytes, z.nbytes)
111-
eq(11, z.initialized)
112+
eq(11, z.nchunks)
113+
eq(11, z.nchunks_initialized)
112114

113115
# check slicing
114116
assert_array_equal(a, np.array(z))
@@ -173,15 +175,15 @@ def test_array_2d(self):
173175
eq(a.shape, z.shape)
174176
eq(a.dtype, z.dtype)
175177
eq((100, 2), z.chunks)
176-
eq(0, z.initialized)
178+
eq(0, z.nchunks_initialized)
177179
eq((10, 5), z.cdata_shape)
178180

179181
# set data
180182
z[:] = a
181183

182184
# check properties
183185
eq(a.nbytes, z.nbytes)
184-
eq(50, z.initialized)
186+
eq(50, z.nchunks_initialized)
185187

186188
# check slicing
187189
assert_array_equal(a, np.array(z))

0 commit comments

Comments
 (0)