Skip to content

Store dispersion trend coefficients as a dict so the dataset can be written to h5ad - #477

Open
raashish1601 wants to merge 1 commit into
scverse:mainfrom
raashish1601:fix/254-h5ad-trend-coeffs
Open

raashish1601 wants to merge 1 commit into
scverse:mainfrom
raashish1601:fix/254-h5ad-trend-coeffs

Conversation

@raashish1601

Copy link
Copy Markdown

Reference Issue or PRs

Fixes #254.

What does your PR implement? Be specific.

dds.write_h5ad() still fails after deseq2() with the current anndata (0.13.4):

IORegistryError: No method registered for writing <class 'pandas.Series'> into <class 'h5py._hl.group.Group'>

The cause is uns["trend_coeffs"] (and uns["vst_trend_coeffs"] after vst()), which are stored as a pd.Series. The varm["replaced"] part of the issue is already gone since replaced moved to var.

This stores both as a plain {"a0": ..., "a1": ...} dict, which anndata can write and read back. Indexing by "a0"/"a1" keeps working for users. dispersion_trend now accepts a dict (Series and arrays still work), and vst_transform reads the coefficients by key, because unpacking a dict would give the keys.

Added test_write_h5ad, which fits, runs VST, writes to h5ad, reads it back and checks the coefficients. It fails on main with the error above. tests/test_pydeseq2.py and tests/test_edge_cases.py pass, and ruff and mypy are clean.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.07%. Comparing base (2ca3b74) to head (0494798).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #477      +/-   ##
==========================================
+ Coverage   86.05%   86.07%   +0.02%     
==========================================
  Files          15       15              
  Lines        1276     1278       +2     
==========================================
+ Hits         1098     1100       +2     
  Misses        178      178              
Files with missing lines Coverage Δ
src/pydeseq2/dds.py 87.67% <100.00%> (+0.04%) ⬆️
src/pydeseq2/dispersions.py 96.84% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@raashish1601

Copy link
Copy Markdown
Author

The py3.14-pre failure is unrelated to this change: every test fails when building an AnnData, because anndata reads pd.options.future.infer_string, which the pandas pre-release now deprecates with a Pandas4Warning (turned into an error by the test settings). The stable jobs pass.

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.

[BUG] Errors saving DeseqDataSet to H5AD

2 participants