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

Added info for Group and Array #2400

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

TomAugspurger
Copy link
Contributor

Quick pass at adding .info to Group and Array. Like 2.x, info is a property, but it will only contain information that's known statically. I've added a Group.info_complete method that actually calls the store to get dynamic information (for group this is children).

I've punted on a similar Array.info_complete. For that, we'll need to expand the Store ABC to give us an nbytes method to get the size of the array in bytes. Maybe similar for the actual number of chunks written. Doable, but separate from this PR I think .

Closes #2135

return template.format(**dataclasses.asdict(self))


def human_readable_size(size: int) -> str:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was taken from the 2.x implementation.

def info(self) -> ArrayInfo:
return self._info()

async def info_complete(self) -> ArrayInfo:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we just don't have this in the API till we implement it (since it's new).

else:
kwargs["codecs"] = str(self.metadata.codecs)
kwargs["data_type"] = str(self.metadata.data_type)
# just regular?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to figure out what to do here for other chunking types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

until we have other chunk grid types, I'd say we can either raise an error here (my preference) or leave this field null.

Copy link
Member

@jhamman jhamman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. A few questions after looking at the initial implementation.

@@ -38,6 +39,7 @@
"AsyncArray",
"AsyncGroup",
"Group",
"GroupInfo",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why we want to put this in the user API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think any object that a user can get through a public API (like zarr.group().info) should be part of the API somewhere, if only to enable things like static typing without using private imports.

I don't have a preference for whether it's in the top-level API like I've added here, or some submodule.

src/zarr/_info.py Outdated Show resolved Hide resolved
else:
kwargs["codecs"] = str(self.metadata.codecs)
kwargs["data_type"] = str(self.metadata.data_type)
# just regular?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

until we have other chunk grid types, I'd say we can either raise an error here (my preference) or leave this field null.

src/zarr/core/array.py Show resolved Hide resolved
)
@property
def info(self) -> ArrayInfo:
return self._async_array.info
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add docstrings here and in info_complete

@TomAugspurger TomAugspurger mentioned this pull request Oct 23, 2024
6 tasks
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

Successfully merging this pull request may close these issues.

[v3] reimplement / develop Group.info and Array.info properties
2 participants