-
-
Notifications
You must be signed in to change notification settings - Fork 282
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
Buffer Prototype Argument #1910
Merged
normanrz
merged 22 commits into
zarr-developers:v3
from
madsbk:buffer_prototype_argument
Jun 4, 2024
Merged
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b897926
move ArraySpec to its own file
madsbk 5c578b2
fix protocol typo
madsbk bc5f616
use NBBuffer instead of factory functions
madsbk e843a6b
as_buffer
madsbk 73e5361
ArraySpec: adding prototype
madsbk 712440a
Prototype
madsbk cb88b98
remove as_buffer() again
madsbk 26069f4
store takes prototype
madsbk 17bdcaa
Remove hack to support v2 tests
madsbk 0ffa32c
test_codecs_use_of_prototype
madsbk 8b9ab51
cleanup
madsbk ec2f994
adding todo mark
madsbk 5d9c52c
doc
madsbk d929b5f
cleanup
madsbk afecd51
Merge branch 'v3' of github.com:zarr-developers/zarr-python into buff…
madsbk 1e28950
Merge branch 'v3' of github.com:zarr-developers/zarr-python into buff…
madsbk 58c9444
doc
madsbk 5a41327
Merge branch 'v3' of github.com:zarr-developers/zarr-python into buff…
madsbk 32edf7b
Merge branch 'v3' of github.com:zarr-developers/zarr-python into buff…
madsbk 7f8d9ec
cleanup
madsbk 563fece
Merge branch 'v3' of github.com:zarr-developers/zarr-python into buff…
madsbk 0aa534f
rename Protocol => BufferProtocol
madsbk 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
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
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,41 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import Any, Literal | ||
|
||
import numpy as np | ||
|
||
from zarr.buffer import Prototype | ||
from zarr.common import ChunkCoords, parse_dtype, parse_fill_value, parse_order, parse_shapelike | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ArraySpec: | ||
shape: ChunkCoords | ||
dtype: np.dtype[Any] | ||
fill_value: Any | ||
order: Literal["C", "F"] | ||
prototype: Prototype | ||
|
||
def __init__( | ||
self, | ||
shape: ChunkCoords, | ||
dtype: np.dtype[Any], | ||
fill_value: Any, | ||
order: Literal["C", "F"], | ||
prototype: Prototype, | ||
) -> None: | ||
shape_parsed = parse_shapelike(shape) | ||
dtype_parsed = parse_dtype(dtype) | ||
fill_value_parsed = parse_fill_value(fill_value) | ||
order_parsed = parse_order(order) | ||
|
||
object.__setattr__(self, "shape", shape_parsed) | ||
object.__setattr__(self, "dtype", dtype_parsed) | ||
object.__setattr__(self, "fill_value", fill_value_parsed) | ||
object.__setattr__(self, "order", order_parsed) | ||
object.__setattr__(self, "prototype", prototype) | ||
|
||
@property | ||
def ndim(self) -> int: | ||
return len(self.shape) |
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.
Is the
Prototype
pickleable?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.
The
default_prototype
, which is the one we use inArrayV3Metadata
, is pickleable.AFAIK, it is not possible to type hint pickable but added the requirement in the docstring.
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.
The thing that has to be pickleable is the class, not the object itself. I'm having a hard time imagining any scenario in which a class is not pickleable.