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

Limit recursion in GroupSpec.from_zarr #2

Closed
clbarnes opened this issue Jul 5, 2023 · 4 comments
Closed

Limit recursion in GroupSpec.from_zarr #2

clbarnes opened this issue Jul 5, 2023 · 4 comments

Comments

@clbarnes
Copy link
Contributor

clbarnes commented Jul 5, 2023

Other than cases of symlink-derived infinite recursion, there might be times where you want to get the GroupSpec for the upper levels of a zarr hierarchy without downloading and parsing every metadata document. I'd envision it something like

class GroupSpec(...)
    ...
    items: Optional[dict[str, ...]]

    @classmethod
    def from_zarr(cls, group, depth=-1):
        attrs = ...
        self = cls(attrs, dict())
        self.update_items(group, depth)
        return self

    def update_items(self, group: zarr.Group, depth=-1):
        if depth == 0:
            self.items = None
            return
       
        self.items = dict()
        for key, obj in group.items():
            if isinstance(obj, zarr.Array):
                items[key] = ArraySpec.from_zarr(obj)
           else:
               items[key] = cls.from_zarr(obj, depth - 1)
            
@d-v-b
Copy link
Collaborator

d-v-b commented Jul 6, 2023

items: Optional[dict[str, ...]]

Does this express the semantics of nullability here?

# there definitely are no subarrays or subgroups
GroupSpec(items={})

# have not checked if there are subarrays or subgroups
GroupSpec(items=None)

@clbarnes
Copy link
Contributor Author

clbarnes commented Jul 6, 2023

Yes, that's the intention; if None, it needs populating, if empty, it's empty.

@d-v-b
Copy link
Collaborator

d-v-b commented Feb 28, 2024

this will be addressed by #25

@d-v-b
Copy link
Collaborator

d-v-b commented Mar 29, 2024

closed by #25

@d-v-b d-v-b closed this as completed Mar 29, 2024
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

2 participants