Skip to content

fix: correctness fixes from the 0.7.0 code review - #217

Merged
timtreis merged 8 commits into
mainfrom
fix/review-correctness
Nov 15, 2026
Merged

timtreis merged 8 commits into
mainfrom
fix/review-correctness

Conversation

@timtreis

Copy link
Copy Markdown
Member

Summary: This PR fixes six correctness problems that a code review of the 0.7.0 changes (v0.6.1 to main) found. Each one has a test that failed on main.

Changes:

  • tl.spatial_regions: it no longer modifies the caller's graph in adata.obsp. Before, removing the diagonal of a graph that stores one changed the shared CSR buffers and left the matrix inconsistent.
    • obsp["distances"] is now rejected like other distance graphs.
    • The log reports convergence correctly when the last sweep converged.
  • Gene values of tl.infercnv with window_size < step: genes outside every window are now left out, as in 0.6.1. Before, they gave 0/0, which produced NaN cell medians, or a ZeroDivisionError off the main thread.
  • Parameters stored in uns[...]["params"]: list-like values (pandas Index or Series, sets) are stored as lists. Before, write_h5ad and write_zarr failed after passing, for example, reference_cat=adata.obs["ct"].cat.categories[:2].
  • tl.ithcna and tl.ithgex on sparse input:
    • Duplicate entries are now summed, and constant rows are left out, as for dense input. This also removes a separate CSR kernel.
    • Only groups that were actually sampled are logged as estimated.
    • Unused categories are left out, as in 0.6.1.
  • Lazy obs from anndata.experimental.read_lazy: tl.cnv_score, the ITH scores, tl.spatial_regions and the fast heatmaps now read group columns through one helper, which also keeps the category order.
  • tl.infercnv input checks:
    • NaN in the expression matrix now raises a clear error. Before, it was silently treated as 0.
    • Genes without a start position are left out and logged.
    • A clear error is raised when no usable chromosome is left.
  • Docs: the settings page no longer mentions a progress bar that was removed.

Testing: The new tests failed on main and pass here. Gene values match infercnvpy 0.6.1 for several window and step combinations. The full suite passes on the HMGU cluster (641 passed, 12 skipped), and so do prek and mypy.

…istances'], logs convergence on the last sweep
…window, as 0.6.1 did

Genes between two windows divided 0/0: NaN gene values for whole cells on the main thread, ZeroDivisionError in the serial kernel. _gene_values now takes the first window and window count per gene from _Layout.
…constant rows, as for a dense one

The CSR standardization kernel ignored duplicate entries and kept constant non-zero rows (rounding in the sum of squares). Densify into the float32 buffer and standardize in place instead; values match the old kernel within 1 ulp.
… from the lazy obs of read_lazy

_obs_column moves to _util and loads one column of a lazy Dataset2D with its categories.
…ries; cnv_score obs_key warning points at the caller

corr_iqr returns whether it sampled, so groups computed exactly after dropping constant cells are not reported as sampled. Unused categories got NaN scores; 0.6.1 left them out.
…nes without a start are left out

NaN in the expression or the reference was read as 'inside the reference band' (0); it now raises. A gene without a start is dropped like a gene without a chromosome (pd.NA crashed, NaN was sorted last); a gene without an end ends at its start (0.6.1 never read end). chrM only, or min_mean leaving no gene on a chr chromosome, raised 'need at least one array to concatenate'.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.17%. Comparing base (f1be2ac) to head (b448723).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #217      +/-   ##
==========================================
+ Coverage   92.96%   93.17%   +0.20%     
==========================================
  Files          21       21              
  Lines        1593     1611      +18     
==========================================
+ Hits         1481     1501      +20     
+ Misses        112      110       -2     
Files with missing lines Coverage Δ
src/infercnvpy/_util.py 90.54% <100.00%> (+0.98%) ⬆️
src/infercnvpy/pl/_chromosome_heatmap.py 96.48% <100.00%> (ø)
src/infercnvpy/tl/_infercnv.py 97.95% <100.00%> (+0.01%) ⬆️
src/infercnvpy/tl/_infercnv_kernels.py 100.00% <ø> (ø)
src/infercnvpy/tl/_ith.py 100.00% <100.00%> (ø)
src/infercnvpy/tl/_scores.py 98.85% <100.00%> (+1.31%) ⬆️
src/infercnvpy/tl/_spatial.py 92.78% <100.00%> (+1.20%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timtreis
timtreis merged commit ea800d5 into main Nov 15, 2026
12 checks passed
@timtreis
timtreis deleted the fix/review-correctness branch November 15, 2026 04:34
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.

2 participants