Skip to content

Commit ffc42b7

Browse files
committed
add object_codec argument
1 parent 8b6df1f commit ffc42b7

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

zarr/creation.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
def create(shape, chunks=True, dtype=None, compressor='default',
1717
fill_value=0, order='C', store=None, synchronizer=None,
1818
overwrite=False, path=None, chunk_store=None, filters=None,
19-
cache_metadata=True, read_only=False, **kwargs):
19+
cache_metadata=True, read_only=False, object_codec=None,
20+
**kwargs):
2021
"""Create an array.
2122
2223
Parameters
@@ -55,6 +56,8 @@ def create(shape, chunks=True, dtype=None, compressor='default',
5556
overhead depending on storage and data access pattern).
5657
read_only : bool, optional
5758
True if array should be protected against modification.
59+
object_codec : Codec, optional
60+
A codec to encode object arrays, only needed if dtype=object.
5861
5962
Returns
6063
-------
@@ -82,8 +85,8 @@ def create(shape, chunks=True, dtype=None, compressor='default',
8285
e.g., `MsgPack` or `Pickle` from `numcodecs`::
8386
8487
>>> from numcodecs import MsgPack
85-
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='object',
86-
... filters=[MsgPack()])
88+
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype=object,
89+
... object_codec=MsgPack())
8790
>>> z
8891
<zarr.core.Array (10000, 10000) object>
8992
@@ -108,7 +111,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
108111
# initialize array metadata
109112
init_array(store, shape=shape, chunks=chunks, dtype=dtype, compressor=compressor,
110113
fill_value=fill_value, order=order, overwrite=overwrite, path=path,
111-
chunk_store=chunk_store, filters=filters)
114+
chunk_store=chunk_store, filters=filters, object_codec=object_codec)
112115

113116
# instantiate array
114117
z = Array(store, path=path, chunk_store=chunk_store, synchronizer=synchronizer,
@@ -340,7 +343,7 @@ def array(data, **kwargs):
340343

341344
def open_array(store, mode='a', shape=None, chunks=True, dtype=None, compressor='default',
342345
fill_value=0, order='C', synchronizer=None, filters=None, cache_metadata=True,
343-
path=None, **kwargs):
346+
path=None, object_codec=None, **kwargs):
344347
"""Open an array using file-mode-like semantics.
345348
346349
Parameters
@@ -376,6 +379,8 @@ def open_array(store, mode='a', shape=None, chunks=True, dtype=None, compressor=
376379
overhead depending on storage and data access pattern).
377380
path : string, optional
378381
Array path within store.
382+
object_codec : Codec, optional
383+
A codec to encode object arrays, only needed if dtype=object.
379384
380385
Returns
381386
-------
@@ -432,15 +437,17 @@ def open_array(store, mode='a', shape=None, chunks=True, dtype=None, compressor=
432437
elif mode == 'w':
433438
init_array(store, shape=shape, chunks=chunks, dtype=dtype,
434439
compressor=compressor, fill_value=fill_value,
435-
order=order, filters=filters, overwrite=True, path=path)
440+
order=order, filters=filters, overwrite=True, path=path,
441+
object_codec=object_codec)
436442

437443
elif mode == 'a':
438444
if contains_group(store, path=path):
439445
err_contains_group(path)
440446
elif not contains_array(store, path=path):
441447
init_array(store, shape=shape, chunks=chunks, dtype=dtype,
442448
compressor=compressor, fill_value=fill_value,
443-
order=order, filters=filters, path=path)
449+
order=order, filters=filters, path=path,
450+
object_codec=object_codec)
444451

445452
elif mode in ['w-', 'x']:
446453
if contains_group(store, path=path):
@@ -450,7 +457,8 @@ def open_array(store, mode='a', shape=None, chunks=True, dtype=None, compressor=
450457
else:
451458
init_array(store, shape=shape, chunks=chunks, dtype=dtype,
452459
compressor=compressor, fill_value=fill_value,
453-
order=order, filters=filters, path=path)
460+
order=order, filters=filters, path=path,
461+
object_codec=object_codec)
454462

455463
# determine read only status
456464
read_only = mode == 'r'

0 commit comments

Comments
 (0)