Skip to content

Commit fa41653

Browse files
committed
document default compressor
1 parent 3e7c70e commit fa41653

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

docs/tutorial.rst

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ compression, level 1::
220220
store: dict
221221

222222
Here is an example using LZMA with a custom filter pipeline including
223-
the delta filter::
223+
LZMA's built-in delta filter::
224224

225225
>>> import lzma
226-
>>> filters = [dict(id=lzma.FILTER_DELTA, dist=4),
227-
... dict(id=lzma.FILTER_LZMA2, preset=1)]
228-
>>> compressor = zarr.LZMA(filters=filters)
226+
>>> lzma_filters = [dict(id=lzma.FILTER_DELTA, dist=4),
227+
... dict(id=lzma.FILTER_LZMA2, preset=1)]
228+
>>> compressor = zarr.LZMA(filters=lzma_filters)
229229
>>> z = zarr.array(np.arange(100000000, dtype='i4').reshape(10000, 10000),
230230
... chunks=(1000, 1000), compressor=compressor)
231231
>>> z
@@ -234,7 +234,28 @@ the delta filter::
234234
compressor: LZMA(format=1, check=-1, preset=None, filters=[{'dist': 4, 'id': 3}, {'preset': 1, 'id': 33}])
235235
store: dict
236236

237-
To disable compression, set ``compressor=None`` when creating an array.
237+
The default compressor can be changed by setting the value of the
238+
``zarr.storage.default_compressor`` variable, e.g.::
239+
240+
>>> import zarr.storage
241+
>>> # switch to using Zstandard via Blosc by default
242+
... zarr.storage.default_compressor = zarr.Blosc(cname='zstd', clevel=1, shuffle=1)
243+
>>> z = zarr.zeros(100000000, chunks=1000000)
244+
>>> z
245+
Array((100000000,), float64, chunks=(1000000,), order=C)
246+
nbytes: 762.9M; nbytes_stored: 302; ratio: 2649006.6; initialized: 0/100
247+
compressor: Blosc(cname='zstd', clevel=1, shuffle=1)
248+
store: dict
249+
>>> # switch back to Blosc defaults
250+
... zarr.storage.default_compressor = zarr.Blosc()
251+
252+
To disable compression, set ``compressor=None`` when creating an array, e.g.::
253+
254+
>>> z = zarr.zeros(100000000, chunks=1000000, compressor=None)
255+
>>> z
256+
Array((100000000,), float64, chunks=(1000000,), order=C)
257+
nbytes: 762.9M; nbytes_stored: 209; ratio: 3827751.2; initialized: 0/100
258+
store: dict
238259

239260
.. _tutorial_filters:
240261

zarr/tests/test_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ def test_np_ufuncs(self):
512512
zi = self.create_array(shape=indices.shape, dtype=indices.dtype,
513513
chunks=10, filters=None)
514514
zi[:] = indices
515+
# this triggers __array__() call with dtype argument
515516
assert_array_equal(np.take(a, indices, axis=1),
516517
np.take(a, zi, axis=1))
517518

zarr/tests/test_hierarchy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def test_getattr(self):
488488
# setup
489489
g1 = self.create_group()
490490
g2 = g1.create_group('foo')
491-
d1 = g2.create_dataset('bar', shape=100)
491+
g2.create_dataset('bar', shape=100)
492492

493493
# test
494494
eq(g1['foo'], g1.foo)

0 commit comments

Comments
 (0)