Skip to content

Commit 2ff1ffe

Browse files
committed
finalize argument compatibility; coverage to 100%
1 parent 22fba10 commit 2ff1ffe

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

docs/tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ provided that all processes have access to a shared file system. E.g.::
325325
... synchronizer=synchronizer)
326326
>>> z
327327
Array((10000, 10000), int32, chunks=(1000, 1000), order=C)
328-
nbytes: 381.5M; nbytes_stored: 323; ratio: 1238390.1; initialized: 0/100
328+
nbytes: 381.5M; nbytes_stored: 326; ratio: 1226993.9; initialized: 0/100
329329
compressor: Blosc(cname='lz4', clevel=5, shuffle=1)
330330
store: DirectoryStore; synchronizer: ProcessSynchronizer
331331

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ setenv =
1212
commands =
1313
python setup.py build_ext --inplace
1414
py27: nosetests -v zarr
15-
py34,py35: nosetests -v --with-coverage --cover-erase --cover-min-percentage=90 --cover-package=zarr --with-doctest --doctest-options=+NORMALIZE_WHITESPACE zarr
15+
py34,py35: nosetests -v --with-coverage --cover-erase --cover-min-percentage=100 --cover-package=zarr --with-doctest --doctest-options=+NORMALIZE_WHITESPACE zarr
1616
py34,py35: python -m doctest -o NORMALIZE_WHITESPACE -o ELLIPSIS docs/tutorial.rst docs/spec/v2.rst
1717
py35: flake8 zarr
1818
python setup.py bdist_wheel

zarr/creation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _handle_kwargs(compressor, fill_value, kwargs):
116116
# assume single argument, e.g., int
117117
compressor = codec_cls(compression_opts)
118118

119-
# be lenient here
119+
# be lenient here if user gives compressor as 'compression'
120120
elif hasattr(compression, 'get_config'):
121121
compressor = compression
122122

zarr/storage.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,18 @@ def init_array(store, shape, chunks, dtype=None, compressor='default',
247247
chunks = normalize_chunks(chunks, shape, dtype.itemsize)
248248
order = normalize_order(order)
249249

250-
# normalize compressor
250+
# obtain compressor config
251251
if compressor == 'none':
252+
# compatibility
252253
compressor = None
253254
elif compressor == 'default':
254255
compressor = default_compressor
255-
elif isinstance(compressor, str):
256-
codec_cls = codec_registry[compressor]
257-
compressor = codec_cls()
258256
if compressor:
259-
compressor_config = compressor.get_config()
257+
try:
258+
compressor_config = compressor.get_config()
259+
except AttributeError:
260+
raise ValueError('bad compressor argument; expected Codec object, '
261+
'found %r' % compressor)
260262
else:
261263
compressor_config = None
262264

zarr/tests/test_creation.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,19 @@ def test_create():
309309
eq((10,), z.chunks)
310310
assert synchronizer is z.synchronizer
311311

312-
# allow string as compressor arg
313-
z = create(100, chunks=10, compressor='zlib')
312+
# don't allow string as compressor arg
313+
with assert_raises(ValueError):
314+
create(100, chunks=10, compressor='zlib')
315+
316+
# compatibility
317+
318+
z = create(100, compression='zlib', compression_opts=9)
314319
eq('zlib', z.compressor.codec_id)
320+
eq(9, z.compressor.level)
321+
322+
z = create(100, compression='default')
323+
eq('blosc', z.compressor.codec_id)
324+
325+
# errors
326+
with assert_raises(ValueError):
327+
create(100, compression=1)

zarr/tests/test_filters.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ def test_array_with_scaleoffset_filter():
5959
# setup
6060
astype = 'u1'
6161
dtype = 'f8'
62-
flt = FixedScaleOffset(scale=10, offset=1000, astype=astype,
63-
dtype=dtype)
62+
flt = FixedScaleOffset(scale=10, offset=1000, astype=astype, dtype=dtype)
6463
filters = [flt]
6564
data = np.linspace(1000, 1001, 34, dtype='f8')
6665

0 commit comments

Comments
 (0)