Skip to content

chore!: add cupy stubs, reject non-csparse cupy matrices - #2716

Merged
flying-sheep merged 7 commits into
mainfrom
fix-types
Oct 22, 2026
Merged

flying-sheep merged 7 commits into
mainfrom
fix-types

Conversation

@flying-sheep

@flying-sheep flying-sheep commented Oct 22, 2026 •

Copy link
Copy Markdown
Member
  1. avoids the | Any in important types at type check time, see Static typing (closes #196) mudata#218
  2. extends (chore): disallow AnnData(...) with non-csr{r,c} matrices/arrays #1829 to cupy

TODO:

  • check the cupy stubs (Claude modified them from the f-a-u stubs I wrote by hand and I need to check if all changes make sense)

  • LLM or coding agent used: Claude Opus 5.5 via Claude Code
  • If one was used, I, a human, have reviewed, understood and tested every changed line
  • Closes #
  • Tests added
  • Release note not necessary because:

@read-the-docs-business

read-the-docs-business Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 anndata | 🛠️ Build #4611029 | 📁 Comparing b82f9a0 against latest (1f3abab)

  🔍 Preview build  

4 files changed
± typing.html
± generated/anndata.abc.CSCDataset.html
± generated/anndata.abc.CSRDataset.html
± release-notes/index.html

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.67568% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.78%. Comparing base (1f3abab) to head (b82f9a0).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/anndata/_core/merge.py 78.12% 7 Missing ⚠️
src/anndata/tests/helpers.py 0.00% 4 Missing ⚠️
src/anndata/_core/sparse_dataset.py 81.81% 2 Missing ⚠️
src/anndata/acc/__init__.py 50.00% 2 Missing ⚠️
src/anndata/_core/raw.py 87.50% 1 Missing ⚠️
src/anndata/_core/views.py 75.00% 1 Missing ⚠️
src/anndata/compat/__init__.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2716      +/-   ##
==========================================
- Coverage   87.67%   85.78%   -1.90%     
==========================================
  Files          49       49              
  Lines        8163     8166       +3     
==========================================
- Hits         7157     7005     -152     
- Misses       1006     1161     +155     
Files with missing lines Coverage Δ
src/anndata/_core/storage.py 95.31% <100.00%> (ø)
src/anndata/_io/specs/lazy_methods.py 96.61% <ø> (ø)
src/anndata/_io/specs/methods.py 92.02% <100.00%> (-0.32%) ⬇️
src/anndata/abc.py 100.00% <100.00%> (ø)
src/anndata/typing.py 95.45% <100.00%> (+0.21%) ⬆️
src/anndata/_core/raw.py 73.96% <87.50%> (-4.74%) ⬇️
src/anndata/_core/views.py 86.14% <75.00%> (-4.87%) ⬇️
src/anndata/compat/__init__.py 85.06% <75.00%> (-4.06%) ⬇️
src/anndata/_core/sparse_dataset.py 89.08% <81.81%> (-1.13%) ⬇️
src/anndata/acc/__init__.py 97.17% <50.00%> (-0.50%) ⬇️
... and 2 more

... and 1 file with indirect coverage changes

@flying-sheep flying-sheep added this to the 0.13.5 milestone Oct 22, 2026
@flying-sheep
flying-sheep marked this pull request as ready for review October 22, 2026 10:51
@flying-sheep flying-sheep changed the title test: add cupy stubs chore!: add cupy stubs, reject non-csparse cupy matrices Oct 22, 2026
@flying-sheep flying-sheep modified the milestones: 0.13.5, 0.14.0 Oct 22, 2026

@Zethson Zethson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I could see a future where we'd want cupy COO support for n-D arrays but that's a long way off. EHRData could benefit from that.

@flying-sheep

Copy link
Copy Markdown
Member Author

should all be done together then, yeah!

@flying-sheep
flying-sheep merged commit 4783f4f into main Oct 22, 2026
25 of 26 checks passed
@flying-sheep
flying-sheep deleted the fix-types branch October 22, 2026 12:13
return ss.csr_array if self.format == "csr" else ss.csc_array
return ss.csr_matrix if self.format == "csr" else ss.csc_matrix

def _construct(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't find this name that descriptive. The earlier memory_format seemed clearer to me (name wise).

sorry I somehow forgot to send this comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

welp, too late now! That method is ugly anyway, it just exists to be a type-relaxed version of memory_format that the type checker accepts when all three member arrays are np.ndarray | cupy.ndarray, would be great if there was a better way

@ilan-gold

Copy link
Copy Markdown
Contributor

I could see a future where we'd want cupy COO support for n-D arrays but that's a long way off. EHRData could benefit from that.

array api (shift the burden to cupy)

Intron7 added a commit to scverse/rapids-singlecell that referenced this pull request Oct 30, 2026
anndata rejects cupyx matrices other than CSR and CSC as X since
scverse/anndata#2716, so the COO case of test_layouts_match fails against
anndata's dev build on main (GPU Tests run 40924525609, hatch-test.dev-13).
A COO matrix cannot enter an AnnData any more; the kernels' own COO fallback
(convert to CSR) stays.

Signed-off-by: Intron7 <[email protected]>
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.

3 participants