Skip to content

Commit deff4c1

Browse files
committed
coverage back to 100
1 parent 069aa62 commit deff4c1

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

requirements_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fasteners==0.14.1
88
flake8==3.3.0
99
mccabe==0.6.1
1010
monotonic==1.2
11+
msgpack-python==0.4.8
1112
nose==1.3.7
1213
numcodecs==0.2.0
1314
numpy==1.12.0

zarr/creation.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,45 @@ def create(shape, chunks=None, dtype=None, compressor='default',
7171
compressor: Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
7272
store: dict
7373
74+
Create an array with different some different configuration options::
75+
76+
>>> from numcodecs import Blosc
77+
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='i1', order='F',
78+
... compressor=Blosc(cname='zstd', clevel=1, shuffle=Blosc.BITSHUFFLE))
79+
>>> z
80+
Array((10000, 10000), int8, chunks=(1000, 1000), order=F)
81+
nbytes: 95.4M; nbytes_stored: ...; ratio: ...; initialized: 0/100
82+
compressor: Blosc(cname='zstd', clevel=1, shuffle=BITSHUFFLE, blocksize=0)
83+
store: dict
84+
85+
To create an array with object dtype requires a filter that can handle Python object encoding,
86+
e.g., `MsgPack` or `Pickle` from `numcodecs`::
87+
88+
>>> from numcodecs import MsgPack
89+
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='object',
90+
... filters=[MsgPack()])
91+
>>> z
92+
Array((10000, 10000), object, chunks=(1000, 1000), order=C)
93+
nbytes: 762.9M; nbytes_stored: ...; ratio: ...; initialized: 0/100
94+
filters: MsgPack(encoding='utf-8')
95+
compressor: Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
96+
store: dict
97+
98+
Example with some filters, and also storing chunks separately from metadata::
99+
100+
>>> from numcodecs import Quantize, Adler32
101+
>>> store, chunk_store = dict(), dict()
102+
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='f8',
103+
... filters=[Quantize(digits=2, dtype='f8'), Adler32()],
104+
... store=store, chunk_store=chunk_store)
105+
>>> z
106+
Array((10000, 10000), float64, chunks=(1000, 1000), order=C)
107+
nbytes: 762.9M; nbytes_stored: ...; ratio: ...; initialized: 0/100
108+
filters: Quantize(digits=2, dtype='<f8')
109+
Adler32()
110+
compressor: Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
111+
store: dict; chunk_store: dict
112+
74113
""" # flake8: noqa
75114

76115
# handle polymorphic store arg

zarr/tests/test_filters.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
Quantize
1212
from zarr.creation import array
1313
from zarr.compat import PY2
14-
from zarr.util import buffer_tobytes
1514

1615

1716
compressors = [
@@ -220,8 +219,8 @@ def test_compressor_as_filter():
220219

221220
# check storage
222221
for i in range(10):
223-
x = buffer_tobytes(a1.store[str(i)])
224-
y = buffer_tobytes(a2.store[str(i)])
222+
x = bytes(a1.store[str(i)])
223+
y = bytes(a2.store[str(i)])
225224
eq(x, y)
226225

227226
# check data

zarr/util.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,3 @@ def buffer_size(v):
293293
else:
294294
v = memoryview(v)
295295
return reduce(operator.mul, v.shape) * v.itemsize
296-
297-
298-
def buffer_tobytes(v):
299-
from array import array as _stdlib_array
300-
if isinstance(v, np.ndarray):
301-
return v.tobytes(order='A')
302-
elif PY2 and isinstance(v, _stdlib_array): # pragma: no cover
303-
return v.tostring()
304-
else:
305-
return memoryview(v).tobytes()

0 commit comments

Comments
 (0)