Skip to content

Conversation

@giovp
Copy link
Member

@giovp giovp commented Dec 20, 2025

Problem

PyDESeq2(..., layer=...) validates the layer at init, but .fit() passed the original AnnData to PyDESeq2, which always reads adata.X. If X is non-integer (e.g. normalized), .fit() fails with ValueError: The count matrix should only contain integers.

Fix

When layer is set, build an internal counts-only AnnData with .X = adata.layers[layer] (no mutation of user .X) and pass that to DeseqDataSet.

Test

Add regression test where .X is non-integer but layer contains integer counts; assert .fit() succeeds and .X is unchanged.

@giovp
Copy link
Member Author

giovp commented Dec 20, 2025

good agent

I would have described it differently but good job for just clicking the mouse 😅

@codecov-commenter
Copy link

codecov-commenter commented Dec 20, 2025

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 71.91%. Comparing base (12897e1) to head (d767b39).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
...y/tools/_differential_gene_expression/_pydeseq2.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #895      +/-   ##
==========================================
- Coverage   73.54%   71.91%   -1.63%     
==========================================
  Files          48       48              
  Lines        5613     5736     +123     
==========================================
- Hits         4128     4125       -3     
- Misses       1485     1611     +126     
Files with missing lines Coverage Δ
...y/tools/_differential_gene_expression/_pydeseq2.py 92.50% <75.00%> (+0.60%) ⬆️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@Zethson Zethson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much!

I generally feel like layer support should rather be improved upstream in pydeseq2 but if you need this now, I'm happy to merge this PR.

@giovp
Copy link
Member Author

giovp commented Dec 22, 2025

Addressed all maintainer feedback:

  • Removed the unnecessary test_adata.copy() in the new regression test (fixture is already per-test).
  • Moved numpy import to module scope (no local import in the test).

Thanks!

@giovp
Copy link
Member Author

giovp commented Dec 22, 2025

it's more that if pertpy accepts layer as argument, then I expect that that would be passed to the underlying pydeseq dataset.

@Zethson Zethson merged commit 06e1c8f into scverse:main Dec 22, 2025
17 of 21 checks passed
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.

3 participants