Conversation
Preserve record itemsize with zero-copy buffer-compatible views, reject object-containing records, and guard read-only C decoder destinations. Add regressions for nested fields, memory layout and output buffers. Fixes zarr-developers#755.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #867 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 905 912 +7
=========================================
+ Hits 905 912 +7
🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #755.
NumPy cannot export a PEP 3118 format for structured arrays containing datetime or timedelta fields. These arrays currently reach the new memoryview path unchanged and fail in Zstd, LZ4 and Blosc.
This change gives buffer-incompatible structured arrays a zero-copy void view with the same record itemsize. It preserves bytes, memory order and caller-owned dtype metadata, including nested and subarray fields. Ordinary structured arrays keep their existing buffer representation. Object-containing records are rejected before exposing raw pointers.
The C decoders also check that caller-supplied output is writable. Without this check, they write through a raw pointer even when an ndarray is marked read-only. This protects the newly supported structured destinations as well as existing numeric destinations.
Tests cover the original reproduction, nested and subarray datetime/timedelta fields, mixed byte order, padding, scalar and multidimensional buffers, C/F layout, no-copy guarantees, read-only inputs and outputs, unaligned destinations, memoryviews and invalid output sizes.
Validation: 237 new tests passed; full suite with optional dependencies 1,108 passed, 21 skipped on both NumPy 2.5.3 and 2.0.2. Ruff and targeted mypy checks pass. Sphinx builds with three pre-existing warnings also reproduced at the base commit. The compatibility module has 100% measured Python line coverage. A separate review rebuilt the patch from the exact-base source and verified the full suite plus 386 additional adversarial cases on both NumPy versions. The full supported-platform matrix and GitHub CI have not run.