-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
variable-sized chunks with zarr v3 #10880
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
Draft
keewis
wants to merge
3
commits into
pydata:main
Choose a base branch
from
keewis:variable-chunking
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.
Draft
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,7 +279,7 @@ async def async_getitem(self, key): | |
| ) | ||
|
|
||
|
|
||
| def _determine_zarr_chunks(enc_chunks, var_chunks, ndim, name): | ||
| def _determine_zarr_chunks(enc_chunks, var_chunks, ndim, name, zarr_format): | ||
| """ | ||
| Given encoding chunks (possibly None or []) and variable chunks | ||
| (possibly None or []). | ||
|
|
@@ -301,15 +301,18 @@ def _determine_zarr_chunks(enc_chunks, var_chunks, ndim, name): | |
| # while dask chunks can be variable sized | ||
| # https://dask.pydata.org/en/latest/array-design.html#chunks | ||
| if var_chunks and not enc_chunks: | ||
| if zarr_format == 3: | ||
| return tuple(var_chunks) | ||
|
|
||
| if any(len(set(chunks[:-1])) > 1 for chunks in var_chunks): | ||
| raise ValueError( | ||
| "Zarr requires uniform chunk sizes except for final chunk. " | ||
| "Zarr v2 requires uniform chunk sizes except for final chunk. " | ||
| f"Variable named {name!r} has incompatible dask chunks: {var_chunks!r}. " | ||
| "Consider rechunking using `chunk()`." | ||
| ) | ||
| if any((chunks[0] < chunks[-1]) for chunks in var_chunks): | ||
| raise ValueError( | ||
| "Final chunk of Zarr array must be the same size or smaller " | ||
| "Final chunk of a Zarr v2 array must be the same size or smaller " | ||
|
Comment on lines
307
to
+315
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 not correct - it's unfortunately not as simple as "Zarr V3 supports variable-length chunking but Zarr V2 doesn't". |
||
| f"than the first. Variable named {name!r} has incompatible Dask chunks {var_chunks!r}." | ||
| "Consider either rechunking using `chunk()` or instead deleting " | ||
| "or modifying `encoding['chunks']`." | ||
|
|
@@ -475,6 +478,7 @@ def extract_zarr_variable_encoding( | |
| var_chunks=variable.chunks, | ||
| ndim=variable.ndim, | ||
| name=name, | ||
| zarr_format=zarr_format, | ||
| ) | ||
| if _zarr_v3() and chunks is None: | ||
| chunks = "auto" | ||
|
|
@@ -853,9 +857,18 @@ def open_store_variable(self, name): | |
| ) | ||
| attributes = dict(attributes) | ||
|
|
||
| if hasattr(zarr_array, "metadata"): | ||
| chunk_grid = zarr_array.metadata.chunk_grid | ||
| chunks = getattr(chunk_grid, "chunk_shapes", None) | ||
| # regular chunk grid | ||
| if chunks is None: | ||
| chunks = chunk_grid.chunk_shape | ||
| else: | ||
| chunks = zarr_array.chunks | ||
|
|
||
| encoding = { | ||
| "chunks": zarr_array.chunks, | ||
| "preferred_chunks": dict(zip(dimensions, zarr_array.chunks, strict=True)), | ||
| "chunks": chunks, | ||
| "preferred_chunks": dict(zip(dimensions, chunks, strict=True)), | ||
| } | ||
|
|
||
| if _zarr_v3(): | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
this check is probably not sufficient