-
-
Notifications
You must be signed in to change notification settings - Fork 438
Fix of #4237 : 'ValueError: Input array must be contiguous' when *cas… #4238
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
raphaeljolivet
wants to merge
9
commits into
zarr-developers:main
Choose a base branch
from
raphaeljolivet:bugfix/4237-cast-value-transpose-input-aray-should-be-contiguous
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.
+51
−1
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f8564b1
Fix cast_value contiguous input when paired with transpose codec
raphaeljolivet 9ac20c7
Move fix to _do_cast. Add release note
raphaeljolivet d8e4b78
Fixing unit test
raphaeljolivet 1b90d55
Merge branch 'main' into bugfix/4237-cast-value-transpose-input-aray-…
d-v-b 08dfe54
Merge branch 'main' into bugfix/4237-cast-value-transpose-input-aray-…
d-v-b d6b6c59
Apply suggestion from @d-v-b
d-v-b 2756169
style: remove trailing whitespace in cast_value comment
d-v-b ef545c5
Merge branch 'main' into bugfix/4237-cast-value-transpose-input-aray-…
d-v-b b59bf65
Merge branch 'main' into bugfix/4237-cast-value-transpose-input-aray-…
d-v-b 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
Some comments aren't visible on the classic Files Changed page.
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,3 @@ | ||
| The codec *cast_value* expects a contiguous numpy array to work properly. | ||
| It used to break when place before or after a *transpose* codec, which produces non-contiguous arrays. | ||
| This fix resolves the issue. |
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 |
|---|---|---|
|
|
@@ -4,10 +4,13 @@ | |
|
|
||
| import numpy as np | ||
| import pytest | ||
| from numpy.testing import assert_array_equal | ||
|
|
||
| import zarr | ||
| from tests.conftest import Expect, ExpectFail | ||
| from zarr.codecs import BytesCodec, TransposeCodec | ||
| from zarr.codecs.cast_value import CastValue | ||
| from zarr.storage import MemoryStore | ||
|
|
||
| try: | ||
| import cast_value_rs # noqa: F401 | ||
|
|
@@ -477,3 +480,45 @@ def test_parse_scalar_map(case: Expect[Any, Any]) -> None: | |
| from zarr.codecs.cast_value import parse_scalar_map | ||
|
|
||
| assert parse_scalar_map(case.input) == case.output | ||
|
|
||
|
|
||
| @requires_cast_value_rs | ||
| def test_enforce_contiguous_arrays() -> None: | ||
| """ | ||
| Transpose codec produces non-contiguous arrays. | ||
| Ensure cast_value makes them contiguous before processing. | ||
| """ | ||
| data = np.arange(20, dtype=np.float32).reshape(5, 2, 2) | ||
|
Contributor
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. can we parametrize this test over the shape of the array? Specifically, we need to test 0-dimensional arrays, because I think the current fix will not work for 0-dim arrays, and we need to do |
||
|
|
||
| def make_array(filters: list[Any]) -> Any: | ||
| return zarr.create_array( | ||
| store=MemoryStore(), | ||
| shape=data.shape, | ||
| dtype=data.dtype, | ||
| chunks=data.shape, | ||
| filters=filters, | ||
| serializer=BytesCodec(endian="little"), | ||
| compressors=None, | ||
| zarr_format=3, | ||
| ) | ||
|
|
||
| # Cast before transpose | ||
| array = make_array( | ||
| [ | ||
| CastValue(data_type="uint16"), | ||
| TransposeCodec(order=(1, 2, 0)), | ||
| ] | ||
| ) | ||
| array[:] = data | ||
| assert_array_equal(array[:], data) | ||
|
|
||
| # Cast after transpose | ||
| array = make_array( | ||
| [ | ||
| TransposeCodec(order=(1, 2, 0)), | ||
| CastValue(data_type="uint16"), | ||
| ] | ||
| ) | ||
|
|
||
| array[:] = data | ||
| assert_array_equal(array[:], data) | ||
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.