Skip to content

feat: honor use_sparse_array_on_read in lazy sparse reads - #2566

Open
Kayaba-Attribution wants to merge 1 commit into
scverse:mainfrom
Kayaba-Attribution:sparse-array-foundation
Open

feat: honor use_sparse_array_on_read in lazy sparse reads#2566
Kayaba-Attribution wants to merge 1 commit into
scverse:mainfrom
Kayaba-Attribution:sparse-array-foundation

Conversation

@Kayaba-Attribution

Copy link
Copy Markdown

Part of #2477 (foundation PR — intentionally does not close the issue; PRs 2-3 follow).

The first, non-breaking step of the cs{r,c}_array migration.

What

  • read_sparse_as_dask (the lazy/dask sparse read path) now honors settings.use_sparse_array_on_read, mirroring the in-memory read path (BackedSparseMatrix.memory_format). It previously hardcoded cs{r,c}_matrix, so lazy/backed reads ignored the setting.
  • Widen Raw.__init__'s X parameter and the Raw.X property return type to CSMatrix | CSArray (they were CSMatrix-only).

Why

Preparation for turning use_sparse_array_on_read on by default: the read paths should agree on the container type first. This removes an inconsistency where in-memory reads honored the setting but lazy reads did not.

Notes

  • Non-breaking: the default (use_sparse_array_on_read = False) is unchanged, so behavior is identical unless a user has already opted in.
  • Added test_read_elem_lazy_honors_sparse_array_setting (csr/csc x array/matrix). The affected modules (test_read.py, test_backed_sparse.py, test_raw.py, test_x.py) pass under --strict-warnings.

  • Closes #
  • Tests added

Make the lazy/dask sparse read path (read_sparse_as_dask) respect
settings.use_sparse_array_on_read, mirroring the in-memory read path, so
lazy/backed reads return cs{r,c}_array consistently instead of always
returning cs{r,c}_matrix. Also widen Raw.X type hints to CSMatrix | CSArray.

Non-breaking foundation for the cs{r,c}_array migration (scverse#2477).
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.48%. Comparing base (6d99886) to head (45ee065).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2566      +/-   ##
==========================================
- Coverage   87.81%   85.48%   -2.33%     
==========================================
  Files          49       49              
  Lines        7799     7801       +2     
==========================================
- Hits         6849     6669     -180     
- Misses        950     1132     +182     
Files with missing lines Coverage Δ
src/anndata/_core/raw.py 76.31% <100.00%> (-4.61%) ⬇️
src/anndata/_io/specs/lazy_methods.py 96.34% <100.00%> (+0.04%) ⬆️

... and 8 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