-
-
Notifications
You must be signed in to change notification settings - Fork 310
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
Array creation with strings for filters, serializer, compressors #2839
Open
brokkoli71
wants to merge
12
commits into
zarr-developers:main
Choose a base branch
from
scalableminds:string-arguments-for-codecs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
79560d5
fix merge
brokkoli71 7619990
add str arguments for filters, serializer, compressors
brokkoli71 daff61a
remove duplicate type check
brokkoli71 1a3a502
fix ruff
brokkoli71 68ac329
update docstrings
brokkoli71 0e227e0
document changes
brokkoli71 de83f92
test_bad_chunk_encoding
brokkoli71 73b32ac
remove unused "type: ignore" comment
brokkoli71 3588a65
remove comment
brokkoli71 74b45bb
update test_v3_chunk_encoding
brokkoli71 1937ee5
update test_invalid_chunk_encoding
brokkoli71 f3bb890
Merge branch 'main' into string-arguments-for-codecs
brokkoli71 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 @@ | ||
Array creation allows string representation of codecs for ``filters``, ``serializer``, and ``compressors``. |
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 |
---|---|---|
|
@@ -3769,23 +3769,23 @@ def _get_default_codecs( | |
|
||
|
||
FiltersLike: TypeAlias = ( | ||
Iterable[dict[str, JSON] | ArrayArrayCodec | numcodecs.abc.Codec] | ||
Iterable[dict[str, JSON] | str | ArrayArrayCodec | numcodecs.abc.Codec] | ||
| ArrayArrayCodec | ||
| Iterable[numcodecs.abc.Codec] | ||
| numcodecs.abc.Codec | ||
| Literal["auto"] | ||
| str | ||
| None | ||
) | ||
CompressorLike: TypeAlias = dict[str, JSON] | BytesBytesCodec | numcodecs.abc.Codec | None | ||
CompressorsLike: TypeAlias = ( | ||
Iterable[dict[str, JSON] | BytesBytesCodec | numcodecs.abc.Codec] | ||
Iterable[dict[str, JSON] | str | BytesBytesCodec | numcodecs.abc.Codec] | ||
| dict[str, JSON] | ||
| BytesBytesCodec | ||
| numcodecs.abc.Codec | ||
| Literal["auto"] | ||
| str | ||
| None | ||
) | ||
SerializerLike: TypeAlias = dict[str, JSON] | ArrayBytesCodec | Literal["auto"] | ||
SerializerLike: TypeAlias = dict[str, JSON] | ArrayBytesCodec | str | ||
|
||
|
||
class ShardsConfigParam(TypedDict): | ||
|
@@ -4053,7 +4053,7 @@ async def create_array( | |
chunk to bytes. | ||
|
||
For Zarr format 3, a "filter" is a codec that takes an array and returns an array, | ||
and these values must be instances of ``ArrayArrayCodec``, or dict representations | ||
and these values must be instances of ``ArrayArrayCodec``, or dict or string representations | ||
of ``ArrayArrayCodec``. | ||
If no ``filters`` are provided, a default set of filters will be used. | ||
These defaults can be changed by modifying the value of ``array.v3_default_filters`` | ||
|
@@ -4264,24 +4264,13 @@ def _parse_chunk_encoding_v2( | |
elif isinstance(compressor, tuple | list) and len(compressor) == 1: | ||
_compressor = parse_compressor(compressor[0]) | ||
else: | ||
if isinstance(compressor, Iterable) and not isinstance(compressor, dict): | ||
msg = f"For Zarr format 2 arrays, the `compressor` must be a single codec. Got an iterable with type {type(compressor)} instead." | ||
raise TypeError(msg) | ||
_compressor = parse_compressor(compressor) | ||
|
||
if filters is None: | ||
_filters = None | ||
elif filters == "auto": | ||
_filters = default_filters | ||
else: | ||
if isinstance(filters, Iterable): | ||
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 is also checked in |
||
for idx, f in enumerate(filters): | ||
if not isinstance(f, numcodecs.abc.Codec): | ||
msg = ( | ||
"For Zarr format 2 arrays, all elements of `filters` must be numcodecs codecs. " | ||
f"Element at index {idx} has type {type(f)}, which is not a numcodecs codec." | ||
) | ||
raise TypeError(msg) | ||
_filters = parse_filters(filters) | ||
|
||
return _filters, _compressor | ||
|
@@ -4305,6 +4294,8 @@ def _parse_chunk_encoding_v3( | |
out_array_array: tuple[ArrayArrayCodec, ...] = () | ||
elif filters == "auto": | ||
out_array_array = default_array_array | ||
elif isinstance(filters, str): | ||
out_array_array = (_parse_array_array_codec(filters),) | ||
else: | ||
maybe_array_array: Iterable[Codec | dict[str, JSON]] | ||
if isinstance(filters, dict | Codec): | ||
|
@@ -4322,6 +4313,8 @@ def _parse_chunk_encoding_v3( | |
out_bytes_bytes: tuple[BytesBytesCodec, ...] = () | ||
elif compressors == "auto": | ||
out_bytes_bytes = default_bytes_bytes | ||
elif isinstance(compressors, str): | ||
out_bytes_bytes = (_parse_bytes_bytes_codec(compressors),) | ||
else: | ||
maybe_bytes_bytes: Iterable[Codec | dict[str, JSON]] | ||
if isinstance(compressors, dict | Codec): | ||
|
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
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.
same