Skip to content

refactor: robustness and cleanup fixes from the 0.7.0 review - #219

Merged
timtreis merged 11 commits into
mainfrom
refactor/review-robustness
Nov 15, 2026
Merged

timtreis merged 11 commits into
mainfrom
refactor/review-robustness

Conversation

@timtreis

Copy link
Copy Markdown
Member

Summary: The last of three PRs with fixes from the review of the 0.7.0 refactor. This one covers the numba kernels, inputs from 0.6, and code cleanup.

Fixes:

  • Kernels run serially inside every dask task, whatever thread or process the scheduler uses. This replaces the serial= arguments with a thread-local scope in _numba.py. Both twins of each kernel use numpy's error model, and the package imports with NUMBA_DISABLE_JIT=1.
  • A backed CSC matrix is read into memory once, with a warning, instead of in full for every row block.
  • Inputs from 0.6 keep working: ithcna with any obsm key, DataFrame CNV matrices, and gtfparse 2.
  • maynard2020_3k reuses the file that infercnvpy 0.6 downloaded into scanpy's datasetdir.

Cleanup:

  • One group-sum kernel with an expm1 flag, a shared noise test and scratch buffers, and one block reader for the drivers.
  • Shared docstring blocks for ithgex/ithcna and the two chromosome heatmaps. The rendered text is unchanged apart from line breaks.
  • FAST_KWARGS comes from the fields of _Options. The legacy heatmaps share one scanpy helper, and the GTF and BioMart readers share one function to merge var.
  • Gene values are written straight into the result instead of through a copy per block.
  • American spelling in the docs, docstrings and messages added since 0.6.1, as 0.6.1 used.

Testing: the full test suite passes on the cluster (697 passed, 12 skipped).

…or both twins, import with NUMBA_DISABLE_JIT

One thread-local scope (`dask_task`) replaces the serial= arguments: the dask task functions enter it, so all
kernels they call (also `_n_unsorted_rows` and the group sums) run their serial twin, on the synchronous scheduler
and in the main thread of a worker process too. The heatmap reads backed and dask blocks with the parallel kernel
on the main thread.
…and scratch, one block reader for the drivers

`_group_sums_*` take an `expm1` flag instead of the `_group_expm1_sums_*` copies (bit-identical, tested).
`_kept` is the noise test of `_center_emit`, `_count_kept` and `_fill_kept`; `_scratch` the buffers of both CNV
kernels. `_Layout` drops `gene_geometry` (derived from `geometry`) and the unused `step`. `_Rows.read_ahead`
yields each block's row range, so infercnv, cnv_score and the heatmap drivers no longer recompute it.
…stead of in full for every row block

anndata reads all of a CSC matrix for any block of rows, so infercnv read it about blocks x passes times (and the
heatmaps and cnv_score once per block). All three read through `_Rows`, which now loads it once as CSR.
… matrices, gtfparse 2

`ithcna(use_rep=key)` falls back to `adata.obsm[key]` (with a FutureWarning) for any key, not only keys starting with
X_. `_as_matrix` takes the values of a DataFrame in obsm, as the 0.6 heatmap and ithcna did. A polars frame from
gtfparse 2 is converted with `to_pandas`, as before 0.7.
…npy heatmap helper, one var merge

`_splice_doc` fills shared blocks into the docstrings of ithgex/ithcna and chromosome_heatmap/summary (rendered text
unchanged apart from line breaks). FAST_KWARGS comes from the fields of `_Options`. legacy_heatmap and legacy_summary
share `_scanpy_heatmap` and are imported directly (no import cycle). The GTF and BioMart functions share `_merge_var`.
…nce 0.6.1, as 0.6.1 used

Prose only: identifiers such as the kernels' `centre` argument and code cells keep their names.
…anpy's datasetdir

0.6 read it from `sc.settings.datasetdir`; 0.7 downloaded it again into the pooch cache. A file there is now used
(pooch still checks its hash). The comment on the download dir claimed this already.
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@codecov-commenter

codecov-commenter commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.22481% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.71%. Comparing base (2d9233b) to head (619a65c).

Files with missing lines Patch % Lines
src/infercnvpy/io/_genepos.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #219      +/-   ##
==========================================
+ Coverage   93.62%   93.71%   +0.08%     
==========================================
  Files          21       21              
  Lines        1631     1638       +7     
==========================================
+ Hits         1527     1535       +8     
+ Misses        104      103       -1     
Files with missing lines Coverage Δ
src/infercnvpy/_numba.py 100.00% <100.00%> (ø)
src/infercnvpy/_util.py 92.04% <100.00%> (+1.50%) ⬆️
src/infercnvpy/datasets/__init__.py 100.00% <100.00%> (+4.76%) ⬆️
src/infercnvpy/io/_scevan.py 79.31% <ø> (ø)
src/infercnvpy/pl/_chromosome_heatmap.py 96.88% <100.00%> (-0.02%) ⬇️
src/infercnvpy/pl/_chromosome_heatmap_legacy.py 100.00% <100.00%> (ø)
src/infercnvpy/pl/_heatmap_kernels.py 98.61% <100.00%> (-0.20%) ⬇️
src/infercnvpy/pl/_spatial.py 92.72% <ø> (ø)
src/infercnvpy/tl/_infercnv.py 97.99% <100.00%> (+0.03%) ⬆️
src/infercnvpy/tl/_infercnv_kernels.py 100.00% <ø> (ø)
... and 4 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timtreis
timtreis merged commit 7635310 into main Nov 15, 2026
12 checks passed
@timtreis
timtreis deleted the refactor/review-robustness branch November 15, 2026 05: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