Skip to content

fix: reject mismatched raw var names in QC metrics - #4364

Open
AkshajKashyap wants to merge 2 commits into
scverse:mainfrom
AkshajKashyap:fix/qc-use-raw-4347
Open

AkshajKashyap wants to merge 2 commits into
scverse:mainfrom
AkshajKashyap:fix/qc-use-raw-4347

Conversation

@AkshajKashyap

Copy link
Copy Markdown

Summary

calculate_qc_metrics(use_raw=True) can select the matrix from .raw while QC masks and variable labels still come from adata.var.

When the two variable axes differ, this can either raise due to a shape mismatch or silently associate QC results with the wrong variables.

This PR takes the conservative approach of requiring adata.raw.var_names and adata.var_names to be identical when use_raw=True. A mismatch now raises before any QC results are written. The same validation applies to describe_obs and describe_var.

Supporting different raw axes would require defining additional alignment and inplace-output semantics, so this PR avoids silently inventing those semantics.

Tests

Regression coverage includes subset and reordered variable axes, return and inplace modes, all three QC entry points, and no partial mutation on failure.

Before: 56 passed, 7 xfailed
After: 68 passed, 7 xfailed

ruff check and ruff format --check pass.

@AkshajKashyap AkshajKashyap changed the title Fix QC metrics with mismatched raw var names fix: reject mismatched raw var names in QC metrics Sep 13, 2026
@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.93%. Comparing base (5f2accb) to head (c884ee2).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##           main    #4364       +/-   ##
=========================================
+ Coverage      0   81.93%   +81.93%     
=========================================
  Files         0      134      +134     
  Lines         0    13034    +13034     
=========================================
+ Hits          0    10680    +10680     
- Misses        0     2354     +2354     
Flag Coverage Δ
hatch-test.low-vers 78.81% <100.00%> (?)
hatch-test.pre 81.80% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/scanpy/preprocessing/_qc.py 96.05% <100.00%> (ø)

... and 133 files with indirect coverage changes

@AkshajKashyap
AkshajKashyap marked this pull request as ready for review September 13, 2026 06:47
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.

calculate_qc_metrics(use_raw=True) labels .raw's matrix with adata.var

1 participant