-
-
Notifications
You must be signed in to change notification settings - Fork 373
Object encoding #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object encoding #212
Changes from 8 commits
fc03507
8b6df1f
ffc42b7
e0d931e
153421c
cac1fd3
1d9cb45
b7f3bd5
e3d7972
810dc56
64ed0af
aac74ff
601510a
607f4c5
d6ce064
eafecd9
78014cb
2bf2cdc
67b0bb0
2835eb2
14ac8d9
f3c0ccf
6c94602
43f4ae0
53968f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,7 +173,7 @@ def _require_parent_group(path, store, chunk_store, overwrite): | |
|
|
||
| def init_array(store, shape, chunks=True, dtype=None, compressor='default', | ||
| fill_value=None, order='C', overwrite=False, path=None, | ||
| chunk_store=None, filters=None): | ||
| chunk_store=None, filters=None, object_codec=None): | ||
| """Initialize an array store with the given configuration. Note that this is a low-level | ||
| function and there should be no need to call this directly from user code. | ||
|
|
||
|
|
@@ -203,6 +203,8 @@ def init_array(store, shape, chunks=True, dtype=None, compressor='default', | |
| for storage of both chunks and metadata. | ||
| filters : sequence, optional | ||
| Sequence of filters to use to encode chunk data prior to compression. | ||
| object_codec : Codec, optional | ||
| A codec to encode object arrays, only needed if dtype=object. | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
@@ -284,12 +286,13 @@ def init_array(store, shape, chunks=True, dtype=None, compressor='default', | |
| _init_array_metadata(store, shape=shape, chunks=chunks, dtype=dtype, | ||
| compressor=compressor, fill_value=fill_value, | ||
| order=order, overwrite=overwrite, path=path, | ||
| chunk_store=chunk_store, filters=filters) | ||
| chunk_store=chunk_store, filters=filters, | ||
| object_codec=object_codec) | ||
|
|
||
|
|
||
| def _init_array_metadata(store, shape, chunks=None, dtype=None, compressor='default', | ||
| fill_value=None, order='C', overwrite=False, path=None, | ||
| chunk_store=None, filters=None): | ||
| chunk_store=None, filters=None, object_codec=None): | ||
|
|
||
| # guard conditions | ||
| if overwrite: | ||
|
|
@@ -334,6 +337,19 @@ def _init_array_metadata(store, shape, chunks=None, dtype=None, compressor='defa | |
| if filters: | ||
| filters_config = [f.get_config() for f in filters] | ||
| else: | ||
| filters_config = [] | ||
|
|
||
| # deal with object encoding | ||
| if dtype == object: | ||
| if object_codec is None: | ||
| raise ValueError('an object_codec is required for object arrays') | ||
| else: | ||
| filters_config.insert(0, object_codec.get_config()) | ||
| elif object_codec is not None: | ||
| raise ValueError('an object_codec is only needed for object arrays') | ||
|
||
|
|
||
| # use null to indicate no filters | ||
| if not filters_config: | ||
| filters_config = None | ||
|
|
||
| # initialize metadata | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be clear, this is more of a general change to how selection works and not something that is specific to
objecttype data (though it likely will be used for that case), correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is necessary to allow storing a list as an item in an object array. I.e.,
...needs this change to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. Meant to put that comment near the
()piece above. The scalar part is clear. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. Yes it is a general thing, although it is really an optimisation for the case of setting a single item, and shouldn't change behaviour for anything other than allowing more flexibility in what kinds of items can be set in object arrays.