-
-
Notifications
You must be signed in to change notification settings - Fork 286
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
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a6ef792
Added group info
TomAugspurger b94bff2
Basic array
TomAugspurger 73ea1d2
fixup
TomAugspurger a3b797d
docs, tests
TomAugspurger 30c4e6a
fixup
TomAugspurger 297a9f3
Merge remote-tracking branch 'upstream/main' into tom/fix/info
TomAugspurger 60a0881
Merge remote-tracking branch 'upstream/main' into tom/fix/info
TomAugspurger 615c025
fixup
TomAugspurger 125129b
docstringsx
TomAugspurger 19fd7ff
Merge remote-tracking branch 'upstream/main' into tom/fix/info
TomAugspurger 5599da3
fixup
TomAugspurger d96c202
chunk info
TomAugspurger 9118056
fixup
TomAugspurger 0aef240
wip - split to chunks_initialized
TomAugspurger 9ecbbd1
Merge remote-tracking branch 'upstream/main' into tom/fix/info
TomAugspurger 73c304a
Merge remote-tracking branch 'upstream/main' into tom/fix/info
TomAugspurger cdb1672
fixup
TomAugspurger 035f53a
fixup
TomAugspurger 447dbe5
update docs
TomAugspurger 2811215
fixup test
TomAugspurger f7cab1d
Merge remote-tracking branch 'upstream/main' into tom/fix/info
TomAugspurger 2d0bdd7
lint
TomAugspurger f30838c
fixup test
TomAugspurger a1479ed
Merge branch 'main' into tom/fix/info
jhamman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import dataclasses | ||
import textwrap | ||
from typing import Any, Literal | ||
|
||
import numcodecs.abc | ||
import numpy as np | ||
|
||
from zarr.abc.codec import Codec | ||
from zarr.core.metadata.v3 import DataType | ||
|
||
|
||
@dataclasses.dataclass(kw_only=True) | ||
class GroupInfo: | ||
""" | ||
Visual summary for a Group. | ||
|
||
Note that this method and its properties is not part of | ||
Zarr's public API. | ||
""" | ||
|
||
_name: str | ||
_type: Literal["Group"] = "Group" | ||
_zarr_format: Literal[2, 3] | ||
_read_only: bool | ||
_store_type: str | ||
_count_members: int | None = None | ||
_count_arrays: int | None = None | ||
_count_groups: int | None = None | ||
|
||
def __repr__(self) -> str: | ||
template = textwrap.dedent("""\ | ||
Name : {_name} | ||
Type : {_type} | ||
Zarr format : {_zarr_format} | ||
Read-only : {_read_only} | ||
Store type : {_store_type}""") | ||
|
||
if self._count_members is not None: | ||
template += "\nNo. members : {_count_members}" | ||
if self._count_arrays is not None: | ||
template += "\nNo. arrays : {_count_arrays}" | ||
if self._count_groups is not None: | ||
template += "\nNo. groups : {_count_groups}" | ||
return template.format(**dataclasses.asdict(self)) | ||
|
||
|
||
def human_readable_size(size: int) -> str: | ||
if size < 2**10: | ||
return f"{size}" | ||
elif size < 2**20: | ||
return f"{size / float(2**10):.1f}K" | ||
elif size < 2**30: | ||
return f"{size / float(2**20):.1f}M" | ||
elif size < 2**40: | ||
return f"{size / float(2**30):.1f}G" | ||
elif size < 2**50: | ||
return f"{size / float(2**40):.1f}T" | ||
else: | ||
return f"{size / float(2**50):.1f}P" | ||
|
||
|
||
def byte_info(size: int) -> str: | ||
if size < 2**10: | ||
return str(size) | ||
else: | ||
return f"{size} ({human_readable_size(size)})" | ||
|
||
|
||
@dataclasses.dataclass(kw_only=True) | ||
class ArrayInfo: | ||
""" | ||
Visual summary for an Array. | ||
|
||
Note that this method and its properties is not part of | ||
Zarr's public API. | ||
""" | ||
|
||
_type: Literal["Array"] = "Array" | ||
_zarr_format: Literal[2, 3] | ||
_data_type: np.dtype[Any] | DataType | ||
_shape: tuple[int, ...] | ||
_chunk_shape: tuple[int, ...] | None = None | ||
_order: Literal["C", "F"] | ||
_read_only: bool | ||
_store_type: str | ||
_compressor: numcodecs.abc.Codec | None = None | ||
_filters: tuple[numcodecs.abc.Codec, ...] | None = None | ||
_codecs: tuple[Codec, ...] | None = None | ||
_count_bytes: int | None = None | ||
_count_bytes_stored: int | None = None | ||
_count_chunks_initialized: int | None = None | ||
|
||
def __repr__(self) -> str: | ||
template = textwrap.dedent("""\ | ||
Type : {_type} | ||
Zarr format : {_zarr_format} | ||
Data type : {_data_type} | ||
Shape : {_shape} | ||
Chunk shape : {_chunk_shape} | ||
Order : {_order} | ||
Read-only : {_read_only} | ||
Store type : {_store_type}""") | ||
|
||
kwargs = dataclasses.asdict(self) | ||
if self._chunk_shape is None: | ||
# for non-regular chunk grids | ||
kwargs["chunk_shape"] = "<variable>" | ||
if self._compressor is not None: | ||
template += "\nCompressor : {_compressor}" | ||
|
||
if self._filters is not None: | ||
template += "\nFilters : {_filters}" | ||
|
||
if self._codecs is not None: | ||
template += "\nCodecs : {_codecs}" | ||
|
||
if self._count_bytes is not None: | ||
template += "\nNo. bytes : {_count_bytes}" | ||
kwargs["_count_bytes"] = byte_info(self._count_bytes) | ||
|
||
if self._count_bytes_stored is not None: | ||
template += "\nNo. bytes stored : {_count_bytes_stored}" | ||
kwargs["_count_stored"] = byte_info(self._count_bytes_stored) | ||
|
||
if ( | ||
self._count_bytes is not None | ||
and self._count_bytes_stored is not None | ||
and self._count_bytes_stored > 0 | ||
): | ||
template += "\nStorage ratio : {_storage_ratio}" | ||
kwargs["_storage_ratio"] = f"{self._count_bytes / self._count_bytes_stored:.1f}" | ||
|
||
if self._count_chunks_initialized is not None: | ||
template += "\nChunks Initialized : {_count_chunks_initialized}" | ||
return template.format(**kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 begroup.metadata.zarr_format
.This class's sole user-facing focus should be the repr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean:
"... we should NOT encourage ..."