-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New chunking approach that never splits encoded chunks #11060
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
Open
jsignell
wants to merge
10
commits into
pydata:main
Choose a base branch
from
jsignell:non-splitting-auto
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.
+270
−6
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e61da90
Add an auto mechanism that doesn't split encoded chunks
jsignell 75c3f51
Forgot self
jsignell eecb8c5
Change from 'auto' to 'preserve'
jsignell 4461f87
Make sure api allows chunks='preserve'
jsignell c58093f
Add types
jsignell 1e85c59
Refactor and add test
jsignell fccd263
Add hypothesis testing
jsignell 478af0e
Tidy up strategy
jsignell a468c4b
Fix up typing
jsignell 20934cd
Move `preserve_chunks` call out of `normalize_chunks`
jsignell 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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| pytest.importorskip("hypothesis") | ||
| # isort: split | ||
|
|
||
| from hypothesis import given | ||
|
|
||
| import xarray.testing.strategies as xrst | ||
| from xarray.namedarray.parallelcompat import ChunkManagerEntrypoint | ||
|
|
||
|
|
||
| class TestPreserveChunks: | ||
| @given(xrst.shape_and_chunks()) | ||
| def test_preserve_all_chunks( | ||
| self, shape_and_chunks: tuple[tuple[int, ...], tuple[int, ...]] | ||
| ) -> None: | ||
| shape, previous_chunks = shape_and_chunks | ||
| typesize = 8 | ||
| target = 1024 * 1024 | ||
|
|
||
| actual = ChunkManagerEntrypoint.preserve_chunks( | ||
| chunks=("preserve",) * len(shape), | ||
| shape=shape, | ||
| target=target, | ||
| typesize=typesize, | ||
| previous_chunks=previous_chunks, | ||
| ) | ||
| for i, chunk in enumerate(actual): | ||
| if chunk != shape[i]: | ||
| assert chunk >= previous_chunks[i] | ||
| assert chunk % previous_chunks[i] == 0 | ||
| assert chunk <= shape[i] | ||
|
|
||
| if actual != shape: | ||
| assert np.prod(actual) * typesize >= 0.5 * target | ||
|
|
||
| @pytest.mark.parametrize("first_chunk", [-1, (), 1]) | ||
| @given(xrst.shape_and_chunks(min_dims=2)) | ||
| def test_preserve_some_chunks( | ||
| self, | ||
| first_chunk: int | tuple[int, ...], | ||
| shape_and_chunks: tuple[tuple[int, ...], tuple[int, ...]], | ||
| ) -> None: | ||
| shape, previous_chunks = shape_and_chunks | ||
| typesize = 4 | ||
| target = 2 * 1024 * 1024 | ||
|
|
||
| actual = ChunkManagerEntrypoint.preserve_chunks( | ||
| chunks=(first_chunk, *["preserve" for _ in range(len(shape) - 1)]), | ||
| shape=shape, | ||
| target=target, | ||
| typesize=typesize, | ||
| previous_chunks=previous_chunks, | ||
| ) | ||
| for i, chunk in enumerate(actual): | ||
| if i == 0: | ||
| if first_chunk == 1: | ||
| assert chunk == 1 | ||
| elif first_chunk == -1: | ||
| assert chunk == shape[i] | ||
| elif first_chunk == (): | ||
| assert chunk == previous_chunks[i] | ||
| elif chunk != shape[i]: | ||
| assert chunk >= previous_chunks[i] | ||
| assert chunk % previous_chunks[i] == 0 | ||
| assert chunk <= shape[i] | ||
|
|
||
| # if we have more than one chunk, make sure the chunks are big enough | ||
| if actual[1:] != shape[1:]: | ||
| assert np.prod(actual) * typesize >= 0.5 * target |
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
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.
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.
These tests are kind of slow.