@@ -173,7 +173,7 @@ def _require_parent_group(path, store, chunk_store, overwrite):
173
173
174
174
def init_array (store , shape , chunks = True , dtype = None , compressor = 'default' ,
175
175
fill_value = None , order = 'C' , overwrite = False , path = None ,
176
- chunk_store = None , filters = None ):
176
+ chunk_store = None , filters = None , object_codec = None ):
177
177
"""Initialize an array store with the given configuration. Note that this is a low-level
178
178
function and there should be no need to call this directly from user code.
179
179
@@ -203,6 +203,8 @@ def init_array(store, shape, chunks=True, dtype=None, compressor='default',
203
203
for storage of both chunks and metadata.
204
204
filters : sequence, optional
205
205
Sequence of filters to use to encode chunk data prior to compression.
206
+ object_codec : Codec, optional
207
+ A codec to encode object arrays, only needed if dtype=object.
206
208
207
209
Examples
208
210
--------
@@ -284,12 +286,13 @@ def init_array(store, shape, chunks=True, dtype=None, compressor='default',
284
286
_init_array_metadata (store , shape = shape , chunks = chunks , dtype = dtype ,
285
287
compressor = compressor , fill_value = fill_value ,
286
288
order = order , overwrite = overwrite , path = path ,
287
- chunk_store = chunk_store , filters = filters )
289
+ chunk_store = chunk_store , filters = filters ,
290
+ object_codec = object_codec )
288
291
289
292
290
293
def _init_array_metadata (store , shape , chunks = None , dtype = None , compressor = 'default' ,
291
294
fill_value = None , order = 'C' , overwrite = False , path = None ,
292
- chunk_store = None , filters = None ):
295
+ chunk_store = None , filters = None , object_codec = None ):
293
296
294
297
# guard conditions
295
298
if overwrite :
@@ -334,6 +337,19 @@ def _init_array_metadata(store, shape, chunks=None, dtype=None, compressor='defa
334
337
if filters :
335
338
filters_config = [f .get_config () for f in filters ]
336
339
else :
340
+ filters_config = []
341
+
342
+ # deal with object encoding
343
+ if dtype == object :
344
+ if object_codec is None :
345
+ raise ValueError ('an object_codec is required for object arrays' )
346
+ else :
347
+ filters_config .insert (0 , object_codec .get_config ())
348
+ elif object_codec is not None :
349
+ raise ValueError ('an object_codec is only needed for object arrays' )
350
+
351
+ # use null to indicate no filters
352
+ if not filters_config :
337
353
filters_config = None
338
354
339
355
# initialize metadata
0 commit comments