Skip to content

Added info for Group and Array#2400

Merged
jhamman merged 24 commits into
zarr-developers:mainfrom
TomAugspurger:tom/fix/info
Nov 11, 2024
Merged

Added info for Group and Array#2400
jhamman merged 24 commits into
zarr-developers:mainfrom
TomAugspurger:tom/fix/info

Conversation

@TomAugspurger

Copy link
Copy Markdown
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

Comment thread src/zarr/_info.py Outdated
return template.format(**dataclasses.asdict(self))


def human_readable_size(size: int) -> str:

Copy link
Copy Markdown
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.

Comment thread src/zarr/core/array.py Outdated
def info(self) -> ArrayInfo:
return self._info()

async def info_complete(self) -> ArrayInfo:

Copy link
Copy Markdown
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).

Comment thread src/zarr/core/array.py

@jhamman jhamman left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/zarr/__init__.py Outdated
Comment thread src/zarr/_info.py Outdated
Comment thread src/zarr/core/array.py
Comment thread src/zarr/core/array.py Outdated
Comment thread src/zarr/core/array.py Outdated
)
@property
def info(self) -> ArrayInfo:
return self._async_array.info

Copy link
Copy Markdown
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
Comment thread src/zarr/__init__.py Outdated
Comment thread src/zarr/core/_info.py Outdated
class ArrayInfo:
type: Literal["Array"] = "Array"
zarr_format: Literal[2, 3]
data_type: str

Copy link
Copy Markdown
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
Comment thread src/zarr/core/_info.py
Zarr's public API.
"""

_name: str

Copy link
Copy Markdown
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.

@jhamman jhamman Nov 10, 2024

Copy link
Copy Markdown
Member

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

@jhamman jhamman left a comment

Copy link
Copy Markdown
Member

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