-
-
Notifications
You must be signed in to change notification settings - Fork 366
Attrs kwarg #1299
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
Closed
Closed
Attrs kwarg #1299
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4a51f81
add attrs kwarg to array and group initialization routines
d-v-b 7470b63
add attrs kwarg to additional wrappers for creation functions
d-v-b 356b038
split out array and group meta key inference functionality
d-v-b a963bb3
add release note
d-v-b 87174c1
add attrs kwarg to more (all)? instances of init_arrays, add types, a…
d-v-b bb59a4e
Merge branch 'main' into attrs_kwarg
d-v-b d548044
use Attributes.put instead of update for initializing attributes, and…
d-v-b 6606bca
Merge branch 'attrs_kwarg' of https://github.com/d-v-b/zarr-python in…
d-v-b cb66c0e
fix types
d-v-b 39f2b35
fix ambitious type hints
d-v-b 7eb7c12
types
d-v-b 66928b2
blacken and make attrs required for internal init_group and init_arra…
d-v-b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| ensure_contiguous_ndarray_like | ||
| ) | ||
| from numcodecs.registry import codec_registry | ||
| from zarr.attrs import Attributes | ||
|
|
||
| from zarr.errors import ( | ||
| MetadataError, | ||
|
|
@@ -62,6 +63,8 @@ | |
| from zarr._storage.store import (_get_hierarchy_metadata, # noqa: F401 | ||
| _get_metadata_suffix, | ||
| _listdir_from_keys, | ||
| _prefix_to_array_attrs_key, | ||
| _prefix_to_group_attrs_key, | ||
| _rename_from_keys, | ||
| _rename_metadata_v3, | ||
| _rmdir_from_keys, | ||
|
|
@@ -300,7 +303,8 @@ def init_array( | |
| chunk_store: Optional[StoreLike] = None, | ||
| filters=None, | ||
| object_codec=None, | ||
| dimension_separator=None, | ||
| dimension_separator: Optional[str] = None, | ||
| attrs: Dict[str, Any] = {} | ||
| ): | ||
| """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. | ||
|
|
@@ -335,6 +339,8 @@ def init_array( | |
| A codec to encode object arrays, only needed if dtype=object. | ||
| dimension_separator : {'.', '/'}, optional | ||
| Separator placed between the dimensions of a chunk. | ||
| attrs : JSON-serializable dict. | ||
| User attributes for the array. Defaults to {}. | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
@@ -430,6 +436,28 @@ def init_array( | |
| object_codec=object_codec, | ||
| dimension_separator=dimension_separator) | ||
|
|
||
| _init_array_attrs(store, path, attrs) | ||
|
|
||
|
|
||
| def _init_array_attrs(store: StoreLike, path: Optional[str], attrs: Dict[str, Any]): | ||
| if len(attrs): | ||
| if path: | ||
| key_prefix = path + '/' | ||
| else: | ||
| key_prefix = '' | ||
| akey = _prefix_to_array_attrs_key(store, key_prefix) | ||
| Attributes(store, key=akey, cache=False).update(attrs) | ||
|
|
||
|
|
||
| def _init_group_attrs(store: StoreLike, path: Optional[str], attrs: Dict[str, Any]): | ||
| if len(attrs): | ||
| if path: | ||
| key_prefix = path + '/' | ||
| else: | ||
| key_prefix = '' | ||
| akey = _prefix_to_group_attrs_key(store, key_prefix) | ||
| Attributes(store, key=akey, cache=False).update(attrs) | ||
|
|
||
|
|
||
| def _init_array_metadata( | ||
| store: StoreLike, | ||
|
|
@@ -598,6 +626,7 @@ def init_group( | |
| overwrite: bool = False, | ||
| path: Path = None, | ||
| chunk_store: Optional[StoreLike] = None, | ||
| attrs: Dict[str, Any] = {}, | ||
| ): | ||
| """Initialize a group store. Note that this is a low-level function and there should be no | ||
| need to call this directly from user code. | ||
|
|
@@ -613,7 +642,8 @@ def init_group( | |
| chunk_store : Store, optional | ||
| Separate storage for chunks. If not provided, `store` will be used | ||
| for storage of both chunks and metadata. | ||
|
|
||
| attrs : JSON-serializable dict. | ||
| User attributes for the group. Defaults to {}. | ||
| """ | ||
|
|
||
| # normalize path | ||
|
|
@@ -633,6 +663,9 @@ def init_group( | |
| _init_group_metadata(store=store, overwrite=overwrite, path=path, | ||
| chunk_store=chunk_store) | ||
|
|
||
| # initialize attrs | ||
| _init_group_attrs(store, path, attrs) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question |
||
|
|
||
| if store_version == 3: | ||
| # TODO: Should initializing a v3 group also create a corresponding | ||
| # empty folder under data/root/? I think probably not until there | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.