Skip to content
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

creating groups from dicts #2685

Open
d-v-b opened this issue Jan 10, 2025 · 0 comments
Open

creating groups from dicts #2685

d-v-b opened this issue Jan 10, 2025 · 0 comments

Comments

@d-v-b
Copy link
Contributor

d-v-b commented Jan 10, 2025

In many applications involving zarr groups, the complete structure of the zarr group is known in advance. That is, the user knows the names + attributes + properties of all the subgroups and sub-arrays. This means a declarative approach to creating "complete" zarr groups would be much more ergonomic than an imperative approach based on repeated calls to create_group and create_array.

A dict like this:

{
'': GroupMetadata(attributes={'is_root': True}),
'/b': GroupMetadata(attributes={'is_root': False}),
'/b/c': ArrayV3Metadata(attributes={'is_root': False}, shape=(10,10), ...),
}

gives a complete specification of a zarr group. As an alternative to constructing this group imperatively, we could use a declarative approach and have a single function that takes a dict like the one above and creates a zarr group from it, e.g.

root_group = bikeshed_group_from_dict(store, group_dict) # creates all the members of the group concurrently
root_group.members(depth=None) # (('b', Group), ('b/c', Array))

This would cut down on the boilerplate required to construct zarr groups, and make effective use of our concurrent APIs when creating large hierarchies. At a minimum, this expressive API would make a lot of our tests shorter.

Curious to hear people's thoughts. I'm working on an implementation of this over in #2665. My current plan is to have a from_flat function in group.py that creates a group from a flat hierarchy representation. I might also consider adding a Group.from_flat classmethod, in case we ever want to build out support for subclassing groups to express "typed groups" (e.g., a group that only contains arrays).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant