16
16
def create (shape , chunks = True , dtype = None , compressor = 'default' ,
17
17
fill_value = 0 , order = 'C' , store = None , synchronizer = None ,
18
18
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 ):
20
21
"""Create an array.
21
22
22
23
Parameters
@@ -55,6 +56,8 @@ def create(shape, chunks=True, dtype=None, compressor='default',
55
56
overhead depending on storage and data access pattern).
56
57
read_only : bool, optional
57
58
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.
58
61
59
62
Returns
60
63
-------
@@ -82,8 +85,8 @@ def create(shape, chunks=True, dtype=None, compressor='default',
82
85
e.g., `MsgPack` or `Pickle` from `numcodecs`::
83
86
84
87
>>> 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())
87
90
>>> z
88
91
<zarr.core.Array (10000, 10000) object>
89
92
@@ -108,7 +111,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
108
111
# initialize array metadata
109
112
init_array (store , shape = shape , chunks = chunks , dtype = dtype , compressor = compressor ,
110
113
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 )
112
115
113
116
# instantiate array
114
117
z = Array (store , path = path , chunk_store = chunk_store , synchronizer = synchronizer ,
@@ -340,7 +343,7 @@ def array(data, **kwargs):
340
343
341
344
def open_array (store , mode = 'a' , shape = None , chunks = True , dtype = None , compressor = 'default' ,
342
345
fill_value = 0 , order = 'C' , synchronizer = None , filters = None , cache_metadata = True ,
343
- path = None , ** kwargs ):
346
+ path = None , object_codec = None , ** kwargs ):
344
347
"""Open an array using file-mode-like semantics.
345
348
346
349
Parameters
@@ -376,6 +379,8 @@ def open_array(store, mode='a', shape=None, chunks=True, dtype=None, compressor=
376
379
overhead depending on storage and data access pattern).
377
380
path : string, optional
378
381
Array path within store.
382
+ object_codec : Codec, optional
383
+ A codec to encode object arrays, only needed if dtype=object.
379
384
380
385
Returns
381
386
-------
@@ -432,15 +437,17 @@ def open_array(store, mode='a', shape=None, chunks=True, dtype=None, compressor=
432
437
elif mode == 'w' :
433
438
init_array (store , shape = shape , chunks = chunks , dtype = dtype ,
434
439
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 )
436
442
437
443
elif mode == 'a' :
438
444
if contains_group (store , path = path ):
439
445
err_contains_group (path )
440
446
elif not contains_array (store , path = path ):
441
447
init_array (store , shape = shape , chunks = chunks , dtype = dtype ,
442
448
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 )
444
451
445
452
elif mode in ['w-' , 'x' ]:
446
453
if contains_group (store , path = path ):
@@ -450,7 +457,8 @@ def open_array(store, mode='a', shape=None, chunks=True, dtype=None, compressor=
450
457
else :
451
458
init_array (store , shape = shape , chunks = chunks , dtype = dtype ,
452
459
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 )
454
462
455
463
# determine read only status
456
464
read_only = mode == 'r'
0 commit comments