Skip to content

fix: fall back to asarray when DLPack export of a read-only index fails; buffer error fix - #2561

Draft
amalia-k510 wants to merge 1 commit into
scverse:mainfrom
amalia-k510:buffer_error_fix
Draft

fix: fall back to asarray when DLPack export of a read-only index fails; buffer error fix#2561
amalia-k510 wants to merge 1 commit into
scverse:mainfrom
amalia-k510:buffer_error_fix

Conversation

@amalia-k510

@amalia-k510 amalia-k510 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Was running into issues with certain scanpy tests when testing with jax arrays. Example:

FAILED tests/test_pca.py::test_mask_defaults[jax_array-float32] - BufferError: Cannot export readonly array since signalling readonly is unsupported by DLPack (supported by newer DLPack version).
FAILED tests/test_pca.py::test_mask_var_argument_equivalence[float32-jax_array] - BufferError: Cannot export readonly array since signalling readonly is unsupported by DLPack (supported by newer DLPack version).
FAILED tests/test_pca.py::test_mask_defaults[jax_array-float64] - BufferError: Cannot export readonly array since signalling readonly is unsupported by DLPack (supported by newer DLPack version).
FAILED tests/test_pca.py::test_mask_var_argument_equivalence[float64-jax_array] - BufferError: Cannot export readonly array since signalling readonly is unsupported by DLPack (supported by newer DLPack version).

This is the same problem we already handle in __array__ a few lines above, where the comment notes we can't round-trip jax arrays through DLPack and should let numpy handle it in asarray instead.

The fix keeps from_dlpack as the fast path and only falls back to asarray if it actually fails. The array API spec says from_dlpack raises BufferError in exactly this case, so catching it is the intended way to handle it.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.84%. Comparing base (c37e213) to head (f604050).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/anndata/compat/__init__.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2561      +/-   ##
==========================================
- Coverage   87.81%   85.84%   -1.97%     
==========================================
  Files          49       49              
  Lines        7799     7802       +3     
==========================================
- Hits         6849     6698     -151     
- Misses        950     1104     +154     
Files with missing lines Coverage Δ
src/anndata/compat/__init__.py 85.71% <50.00%> (-4.64%) ⬇️

... and 7 files with indirect coverage changes

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.

1 participant