Skip to content

feat: array-api compatibility - #2063

Closed
ilan-gold wants to merge 6 commits into
mainfrom
ig/array_api_starter
Closed

ilan-gold wants to merge 6 commits into
mainfrom
ig/array_api_starter

Conversation

@ilan-gold

@ilan-gold ilan-gold commented Jul 29, 2025 •

Copy link
Copy Markdown
Contributor

@amalia-k510 I will be out for 2.5 weeks starting tomorrow. Please have a look at this branch and work off of it.

There are three commits:

  1. 21d5882 adds some tests that should (and do) fail because we have no handling.
  2. 7cd6d69 adds the has_xp function and uses it to both raise a more informative error for indexing with an array-api compatible object and resolve two of the test fail cases from 21d5882 so that now we can declare AnnData objects that have array-api compatible arrays (in this case, jax)
  3. eff9dde builds off the solved problem in 7cd6d69 and now adds a test indexing into such a declared object. This test now fails because we have no way of creating views of array-api compatible objects. In general views are not part of the array-api so our view mechanism will just be "subset the data"
  4. I implemented the as_view function for the array-api-detected objects in b230d11 and added some more tests in 692a270

So the todos are likely now (in no particular order):

For each of these, the paradigm should be "create (simple) test case, fix the issue the test raises"

  • Closes #
  • Tests added
  • Release note added (or unnecessary)

@codecov

codecov Bot commented Jul 29, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 31.71%. Comparing base (7ff7e3b) to head (b52e5b7).
⚠️ Report is 137 commits behind head on main.

Files with missing lines Patch % Lines
src/anndata/compat/__init__.py 0.00% 7 Missing ⚠️
src/anndata/_core/index.py 0.00% 5 Missing ⚠️
src/anndata/_core/storage.py 0.00% 3 Missing ⚠️
src/anndata/_core/views.py 0.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (7ff7e3b) and HEAD (b52e5b7). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (7ff7e3b) HEAD (b52e5b7)
5 1
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2063       +/-   ##
===========================================
- Coverage   86.81%   31.71%   -55.10%     
===========================================
  Files          46       46               
  Lines        7052     7066       +14     
===========================================
- Hits         6122     2241     -3881     
- Misses        930     4825     +3895     
Files with missing lines Coverage Δ
src/anndata/_core/views.py 28.87% <0.00%> (-62.27%) ⬇️
src/anndata/_core/storage.py 29.54% <0.00%> (-68.08%) ⬇️
src/anndata/_core/index.py 44.44% <0.00%> (-48.22%) ⬇️
src/anndata/compat/__init__.py 28.44% <0.00%> (-52.29%) ⬇️

... and 40 files with indirect coverage changes

@ilan-gold ilan-gold added this to the 0.13.0 milestone Jul 29, 2025
@katosh katosh mentioned this pull request Jan 4, 2026
2 of 3 tasks
@ilan-gold ilan-gold closed this Jan 7, 2026
katosh added a commit to settylab/anndata that referenced this pull request Feb 10, 2026
Two-tier detection: tier 1 uses the canonical has_xp() protocol check
from anndata.compat (catches JAX, numpy >=2.0); tier 2 falls back to
duck-typing (shape/dtype/ndim) for arrays that don't yet implement the
full protocol (PyTorch, TensorFlow). Also uses __array_namespace__()
for backend label resolution and updates stale PR scverse#2063 → scverse#2071.
@ilan-gold ilan-gold modified the milestones: 0.13.0, 0.14.0 Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant