Skip to content

Commit a576dcf

Browse files
committed
doco; repr tweaks
1 parent 64621d5 commit a576dcf

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

README.rst

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ Create an array::
4242

4343
>>> import numpy as np
4444
>>> import zarr
45-
>>> z = zarr.empty((10000, 1000), dtype='i4', chunks=(1000, 100))
45+
>>> z = zarr.empty(shape=(10000, 1000), dtype='i4', chunks=(1000, 100))
4646
>>> z
4747
zarr.ext.SynchronizedArray((10000, 1000), int32, chunks=(1000, 100))
48-
cname: 'blosclz'; clevel: 5; shuffle: 1 (BYTESHUFFLE)
48+
cname: blosclz; clevel: 5; shuffle: 1 (BYTESHUFFLE)
4949
nbytes: 38.1M; cbytes: 0; initialized: 0/100
5050

5151
Fill it with some data::
5252

5353
>>> z[:] = np.arange(10000000, dtype='i4').reshape(10000, 1000)
5454
>>> z
5555
zarr.ext.SynchronizedArray((10000, 1000), int32, chunks=(1000, 100))
56-
cname: 'blosclz'; clevel: 5; shuffle: 1 (BYTESHUFFLE)
56+
cname: blosclz; clevel: 5; shuffle: 1 (BYTESHUFFLE)
5757
nbytes: 38.1M; cbytes: 2.0M; ratio: 19.3; initialized: 100/100
5858

5959
Obtain a NumPy array by slicing::
@@ -88,12 +88,12 @@ Resize the array and add more data::
8888
>>> z.resize(20000, 1000)
8989
>>> z
9090
zarr.ext.SynchronizedArray((20000, 1000), int32, chunks=(1000, 100))
91-
cname: 'blosclz'; clevel: 5; shuffle: 1 (BYTESHUFFLE)
91+
cname: blosclz; clevel: 5; shuffle: 1 (BYTESHUFFLE)
9292
nbytes: 76.3M; cbytes: 2.0M; ratio: 38.5; initialized: 100/200
9393
>>> z[10000:, :] = np.arange(10000000, dtype='i4').reshape(10000, 1000)
9494
>>> z
9595
zarr.ext.SynchronizedArray((20000, 1000), int32, chunks=(1000, 100))
96-
cname: 'blosclz'; clevel: 5; shuffle: 1 (BYTESHUFFLE)
96+
cname: blosclz; clevel: 5; shuffle: 1 (BYTESHUFFLE)
9797
nbytes: 76.3M; cbytes: 4.0M; ratio: 19.3; initialized: 200/200
9898

9999
For convenience, an ``append()`` method is also available, which can be used to
@@ -103,19 +103,34 @@ append data to any axis::
103103
>>> z = zarr.array(a, chunks=(1000, 100))
104104
>>> z
105105
zarr.ext.SynchronizedArray((10000, 1000), int32, chunks=(1000, 100))
106-
cname: 'blosclz'; clevel: 5; shuffle: 1 (BYTESHUFFLE)
106+
cname: blosclz; clevel: 5; shuffle: 1 (BYTESHUFFLE)
107107
nbytes: 38.1M; cbytes: 2.0M; ratio: 19.3; initialized: 100/100
108108
>>> z.append(a+a)
109109
>>> z
110110
zarr.ext.SynchronizedArray((20000, 1000), int32, chunks=(1000, 100))
111-
cname: 'blosclz'; clevel: 5; shuffle: 1 (BYTESHUFFLE)
111+
cname: blosclz; clevel: 5; shuffle: 1 (BYTESHUFFLE)
112112
nbytes: 76.3M; cbytes: 3.6M; ratio: 21.2; initialized: 200/200
113113
>>> z.append(np.vstack([a, a]), axis=1)
114114
>>> z
115115
zarr.ext.SynchronizedArray((20000, 2000), int32, chunks=(1000, 100))
116-
cname: 'blosclz'; clevel: 5; shuffle: 1 (BYTESHUFFLE)
116+
cname: blosclz; clevel: 5; shuffle: 1 (BYTESHUFFLE)
117117
nbytes: 152.6M; cbytes: 7.6M; ratio: 20.2; initialized: 400/400
118118

119+
Create a persistent array (data saved to disk)::
120+
121+
>>> import tempfile
122+
>>> path = 'example.zarr'
123+
>>> z = zarr.open(path, shape=(10000, 1000), dtype='i4', chunks=(1000, 100))
124+
>>> z[:] = np.arange(10000000, dtype='i4').reshape(10000, 1000)
125+
>>> z
126+
zarr.ext.PersistentArray((10000, 1000), int32, chunks=(1000, 100))
127+
cname: blosclz; clevel: 5; shuffle: 1 (BYTESHUFFLE)
128+
nbytes: 38.1M; cbytes: 2.0M; ratio: 19.3; initialized: 100/100
129+
mode: a; path: example.zarr
130+
131+
There is no need to close a persistent array. Data are automatically flushed
132+
to disk.
133+
119134
Tuning
120135
------
121136

zarr/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import absolute_import, print_function, division
33

44

5-
from zarr.core import empty, zeros, ones, full, array
5+
from zarr.core import empty, zeros, ones, full, array, open
66
from zarr import defaults
77
from zarr import constants
88
from zarr.version import version as __version__

zarr/core.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,15 @@ def array(data, chunks=None, dtype=None, cname=None, clevel=None,
231231
z[:] = data
232232

233233
return z
234+
235+
236+
def open(path, mode='a', shape=None, chunks=None, dtype=None, cname=None,
237+
clevel=None, shuffle=None, fill_value=None):
238+
"""TODO"""
239+
240+
# TODO synchronized option
241+
242+
cls = _ext.PersistentArray
243+
return cls(path=path, mode=mode, shape=shape, chunks=chunks, dtype=dtype,
244+
cname=cname, clevel=clevel, shuffle=shuffle,
245+
fill_value=fill_value)

zarr/ext.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ cdef class BaseArray:
869869
r += ', %s' % str(self._dtype)
870870
r += ', chunks=%s' % str(self._chunks)
871871
r += ')'
872-
r += '\n cname: %r' % str(self._cname, 'ascii')
872+
r += '\n cname: %s' % str(self._cname, 'ascii')
873873
r += '; clevel: %s' % self._clevel
874874
r += '; shuffle: %s' % _repr_shuffle[self._shuffle]
875875
r += '\n nbytes: %s' % _util.human_readable_size(self.nbytes)
@@ -1171,7 +1171,7 @@ cdef class PersistentArray(BaseArray):
11711171
self._cdata[cidx] = self.create_chunk(cidx)
11721172

11731173
def _create(self, path, shape=None, chunks=None, dtype=None,
1174-
cname=None, clevel=None, shuffle=None, fill_value=None):
1174+
cname=None, clevel=None, shuffle=None, fill_value=None):
11751175

11761176
# create directories
11771177
data_path = os.path.join(path, defaults.datapath)
@@ -1289,7 +1289,7 @@ cdef class PersistentArray(BaseArray):
12891289

12901290
def __repr__(self):
12911291
r = super(PersistentArray, self).__repr__()
1292-
r += '\n path: %s' % self._path
1292+
r += '\n mode: %s; path: %s' % (self._mode, self._path)
12931293
return r
12941294

12951295
def iter_chunks(self):

0 commit comments

Comments
 (0)