Skip to content

Fix structured datetime and timedelta buffer coercion - #867

Open
loaff123 wants to merge 1 commit into
zarr-developers:mainfrom
loaff123:fix/structured-datetime-buffers
Open

loaff123 wants to merge 1 commit into
zarr-developers:mainfrom
loaff123:fix/structured-datetime-buffers

Conversation

@loaff123

@loaff123 loaff123 commented Oct 1, 2026

Copy link
Copy Markdown

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.

  • Unit tests
  • Available tests pass locally
  • Release note in docs/release.md
  • Documentation build (existing warnings documented)
  • GitHub Actions CI
  • Codecov validation

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

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1f83681) to head (d8103b8).

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     
Files with missing lines Coverage Δ
src/numcodecs/compat.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ensure_contiguous_memoryview has trouble with numpy M data type in a structured array.

1 participant