Skip to content

fix: promote sparse data dtypes in concat_on_disk - #2772

Open
hyouo wants to merge 2 commits into
scverse:mainfrom
hyouo:fix/concat-on-disk-data-dtype
Open

hyouo wants to merge 2 commits into
scverse:mainfrom
hyouo:fix/concat-on-disk-data-dtype

Conversation

@hyouo

@hyouo hyouo commented Dec 1, 2026

Copy link
Copy Markdown

concat_on_disk uses the first sparse block's dtype for the output. When an int8 input is followed by int32 values [300, 400], the output contains [127, 127] in H5AD or [44, -112] in Zarr. Fractional values and missing-value fills can also be lost.

Determine a common dtype from all inputs after reindexing, then convert each block before writing or appending. Empty sparse matrices account for promotion caused by fills without reading input values. Converting every block also fixes HDF5 errors when appending real blocks to complex output.

Functional verification

Wrote small annotated AnnData batches to H5AD and Zarr, concatenated them through the public API with a small chunk budget, and reopened the output files. Compared X and the counts layer separately against explicit expected arrays:

  • Integer values [300, 400] remain intact and sum to 700.
  • Fractional values 0.5 and 1.25 survive while the separate counts layer stays integer.
  • Missing genes receive the requested NaN or 0.5 after gene reordering.
  • Chunked real/complex inputs finish writing and preserve imaginary components.

Also checked cell and gene labels, concatenation along the gene axis, an empty first batch, and integer inputs with an unused NaN fill. Regression tests and project checks pass.

Related work: #2636 proposes pairwise support; #2558 handles missing mapping keys and touches the same writer.

Checklist

  • Tests included.
  • Release note included.
  • LLM or coding agent used: GPT-6 Astra Pro via ChatGPT.
  • If one was used, I, a human, have reviewed, understood and tested every changed line

@read-the-docs-community

read-the-docs-community Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 anndata | 🛠️ Build #36299959 | 📁 Comparing 3572786 against latest (f50632a)

  🔍 Preview build  

1 file changed
± release-notes/index.html

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.54%. Comparing base (f50632a) to head (3572786).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2772      +/-   ##
==========================================
- Coverage   88.60%   86.54%   -2.07%     
==========================================
  Files          51       51              
  Lines        8892     8901       +9     
==========================================
- Hits         7879     7703     -176     
- Misses       1013     1198     +185     
Files with missing lines Coverage Δ
src/anndata/experimental/merge.py 90.69% <100.00%> (+0.33%) ⬆️

... and 9 files with indirect coverage changes

This branch has not been deployed

No deployments
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