Fix of #4237 : 'ValueError: Input array must be contiguous' when *cas… - #4238
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4238 +/- ##
=======================================
Coverage 94.00% 94.00%
=======================================
Files 91 91
Lines 12795 12795
=======================================
Hits 12028 12028
Misses 767 767
🚀 New features to boost your workflow:
|
Use np.ascontiguousarray before calling cast-value-rs, and add regression tests for cast_value + transpose filter orderings. Fixes zarr-developers#4237
212fd4a to
f8564b1
Compare
| arr = chunk_array.as_ndarray_like() | ||
| target_native = self.dtype.to_native_dtype() | ||
|
|
||
| result = self._do_cast( |
There was a problem hiding this comment.
can you move the fix into _do_cast?
|
|
||
| import numpy as np | ||
| import pytest | ||
| from numpy.ma.testutils import assert_array_equal |
There was a problem hiding this comment.
| from numpy.ma.testutils import assert_array_equal | |
| from numpy.testing import assert_array_equal |
| ] | ||
| ) | ||
|
|
||
| # Write should be ok |
There was a problem hiding this comment.
not sure we need these comments -- the entire test should pass, right?
|
thank you for this! can you add a release note? |
…should-be-contiguous
…should-be-contiguous
| 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) |
There was a problem hiding this comment.
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 np.asarray(order="C") instead of np.ascontiguousarray.
Assisted-by: ClaudeCode:claude-opus-5
…should-be-contiguous
|
@raphaeljolivet can you check the failing example against the branch in this PR: #4260? If that fixes the bug, then maybe this PR can simplify to just adding tests? |
…should-be-contiguous
Regression test for zarr-developers#4237: a cast_value codec on either side of a transpose codec must round-trip, because transpose hands the next codec a non-row-major view. Imported unchanged from zarr-developers#4238, where this test was written. The np.ascontiguousarray workaround that accompanied it there is deliberately left out: cast-value-rs 0.4.2 normalizes layout itself, and the workaround promotes 0-d arrays to shape (1,), breaking 0-d arrays. Co-authored-by: Raphael Jolivet <raphael.jolivet@minesparis.psl.eu> Assisted-by: ClaudeCode:claude-fable-5
* deps: bump cast-value.rs to >= 0.4.2 * deps: update uv.lock for cast-value-rs >= 0.4.2 The pyproject floor alone left uv.lock pinning 0.4.0, so any lock-honoring install (uv sync --locked/--frozen) kept the version that silently transposes non-row-major input. Assisted-by: ClaudeCode:claude-fable-5 * fix(cast_value): enforce the cast-value-rs floor at runtime The pyproject floor only binds installs that go through the zarr[cast-value-rs] extra. An environment that already has an older cast-value-rs installed kept silently corrupting non-row-major input after upgrading zarr, which is the failure this floor exists to stop. Check the installed version at import and raise from _do_cast, so the error surfaces when the codec is used rather than breaking `import zarr` for everyone else. A backend without distribution metadata (a `maturin develop` build) has no version to compare and is left alone. Assisted-by: ClaudeCode:claude-fable-5 * test(cast_value): cover cast_value next to the transpose codec Regression test for #4237: a cast_value codec on either side of a transpose codec must round-trip, because transpose hands the next codec a non-row-major view. Imported unchanged from #4238, where this test was written. The np.ascontiguousarray workaround that accompanied it there is deliberately left out: cast-value-rs 0.4.2 normalizes layout itself, and the workaround promotes 0-d arrays to shape (1,), breaking 0-d arrays. Co-authored-by: Raphael Jolivet <raphael.jolivet@minesparis.psl.eu> Assisted-by: ClaudeCode:claude-fable-5 --------- Co-authored-by: Raphael Jolivet <contact@raphael-jolivet.name> Co-authored-by: Raphael Jolivet <raphael.jolivet@minesparis.psl.eu>
|
sorry for the churn @raphaeljolivet but I think some of these changes are superseded by #4260, please have a look |
Fix of #4237 with unit test.