-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Improved type hinting using zarr-metadata #38
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c088a94
add zarr-metadata package
kylebarron f716aee
link to zarr-metadata based types
kylebarron 4ee0870
known first party
kylebarron 69bfad6
add ruff format check on ci
kylebarron be33789
cleaner type hint for crc32 config
kylebarron 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,31 +1,56 @@ | ||
| from typing import Any, Literal, TypeAlias | ||
| from typing import TypeAlias | ||
|
|
||
| DataTypeName: TypeAlias = Literal[ | ||
| "bool", | ||
| "int8", | ||
| "int16", | ||
| "int32", | ||
| "int64", | ||
| "uint8", | ||
| "uint16", | ||
| "uint32", | ||
| "uint64", | ||
| "float16", | ||
| "float32", | ||
| "float64", | ||
| "complex64", | ||
| "complex128", | ||
| "string", | ||
| "bytes", | ||
| ] | ||
| """The Zarr v3 names of the built-in fixed data types. | ||
| from zarr_metadata import NamedConfigV3 | ||
| from zarr_metadata.v3.data_type import ( | ||
| BoolDataTypeName, | ||
| BytesDataTypeName, | ||
| Complex64DataTypeName, | ||
| Complex128DataTypeName, | ||
| Float16DataTypeName, | ||
| Float32DataTypeName, | ||
| Float64DataTypeName, | ||
| Int8DataTypeName, | ||
| Int16DataTypeName, | ||
| Int32DataTypeName, | ||
| Int64DataTypeName, | ||
| RawBytesDataTypeName, | ||
| StringDataTypeName, | ||
| Uint8DataTypeName, | ||
| Uint16DataTypeName, | ||
| Uint32DataTypeName, | ||
| Uint64DataTypeName, | ||
| ) | ||
|
|
||
| DataTypeName: TypeAlias = ( | ||
| BoolDataTypeName | ||
| | Int8DataTypeName | ||
| | Int16DataTypeName | ||
| | Int32DataTypeName | ||
| | Int64DataTypeName | ||
| | Uint8DataTypeName | ||
| | Uint16DataTypeName | ||
| | Uint32DataTypeName | ||
| | Uint64DataTypeName | ||
| | Float16DataTypeName | ||
| | Float32DataTypeName | ||
| | Float64DataTypeName | ||
| | Complex64DataTypeName | ||
| | Complex128DataTypeName | ||
| | StringDataTypeName | ||
| | BytesDataTypeName | ||
| | RawBytesDataTypeName | ||
| ) | ||
| """The Zarr v3 names of the data types `from_string` can build. | ||
|
|
||
| Composed from the per-dtype name literals in `zarr_metadata.v3.data_type`, so | ||
| it stays in sync with the spec rather than being hand-maintained here. | ||
|
Comment on lines
+24
to
+46
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now we define our own explicit dtype union, cc @d-v-b |
||
| """ | ||
|
|
||
| class DataType: | ||
| """A Zarr v3 data type.""" | ||
|
|
||
| @staticmethod | ||
| def from_metadata(metadata: dict[str, Any]) -> DataType: | ||
| def from_metadata(metadata: NamedConfigV3) -> DataType: | ||
| """Construct a data type from its Zarr v3 metadata.""" | ||
| @staticmethod | ||
| def from_string(name: DataTypeName | str) -> DataType: | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| from typing import Any | ||
| from zarr_metadata import MetadataV3, NamedConfigV3 | ||
|
|
||
| class CodecChain: | ||
| """The ordered chain of codecs used to encode and decode an array's chunks.""" | ||
|
|
||
| def __init__(self, metadatas: list[dict[str, Any]]) -> None: | ||
| def __init__(self, metadatas: list[MetadataV3]) -> None: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this |
||
| """Construct a codec chain from a list of Zarr v3 codec metadata.""" | ||
| def create_metadatas(self) -> list[dict[str, Any]]: | ||
| def create_metadatas(self) -> list[NamedConfigV3]: | ||
| """Return the Zarr v3 metadata for each codec in the chain.""" | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import pytest | ||
|
|
||
| from zarrista import DataType | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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.
Ideally upstream
zarr-metadatawill add its own type union, cc @d-v-b