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

Merged
merged 24 commits into from
Nov 11, 2024
Merged

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).

src/zarr/core/array.py Show resolved Hide resolved
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.

src/zarr/__init__.py Outdated Show resolved Hide resolved
src/zarr/_info.py Outdated Show resolved Hide resolved
src/zarr/core/array.py Show resolved Hide resolved
src/zarr/core/array.py Outdated 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
src/zarr/__init__.py Outdated Show resolved Hide resolved
class ArrayInfo:
type: Literal["Array"] = "Array"
zarr_format: Literal[2, 3]
data_type: 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.

For this, compressor, filters, codecs, and maybe store_type pick whether we want the string repr as an argument or the concrete value. I think initially I wanted to use concrete values for everything, which gives us a bit more flexiblity at formatting time (we can always call str then if we just want the string repr).

I'll look into why I switched over to strs for these.

@TomAugspurger TomAugspurger marked this pull request as ready for review November 8, 2024 16:39
Zarr's public API.
"""

_name: 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.

I've made all these fields private.

IMO, we should encourage things like group.info.zarr_format. The one place for that information should be group.metadata.zarr_format.

This class's sole user-facing focus should be the repr.

Copy link
Member

@jhamman jhamman Nov 10, 2024

Choose a reason for hiding this comment

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

IMO, we should encourage things like group.info.zarr_format.

Did you mean:

"... we should NOT encourage ..."

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.

Thanks @TomAugspurger !

@jhamman jhamman merged commit e5135f9 into zarr-developers:main Nov 11, 2024
26 checks passed
DimitriPapadopoulos added a commit to DimitriPapadopoulos/zarr-python that referenced this pull request Nov 12, 2024
DimitriPapadopoulos added a commit to DimitriPapadopoulos/zarr-python that referenced this pull request Nov 12, 2024
@DimitriPapadopoulos DimitriPapadopoulos mentioned this pull request Nov 12, 2024
6 tasks
d-v-b pushed a commit that referenced this pull request Nov 12, 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

Successfully merging this pull request may close these issues.

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