Skip to content

Fix type errors surfaced by anndata 0.13 - #456

Merged
Zethson merged 1 commit into
mainfrom
fix-anndata-013-typing
Sep 6, 2026
Merged

Zethson merged 1 commit into
mainfrom
fix-anndata-013-typing

Conversation

@Zethson

@Zethson Zethson commented Sep 6, 2026

Copy link
Copy Markdown
Member

anndata 0.13 ships inline type information, so mypy now checks the AnnData attributes DeseqDataSet inherits, which turned main red with 228 errors. Narrows those attributes to the in-memory types PyDESeq2 actually holds, swaps Series.values for to_numpy(), and casts where anndata's union is wider than what the class constructs; runtime behaviour is unchanged and mypy, ruff and the tests pass.

anndata 0.13 ships inline type information, so `ad.AnnData` is no longer `Any`
to mypy and the attributes `DeseqDataSet` inherits from it are checked for the
first time. That surfaced 228 errors on main, none of which are new bugs.

`X`, `obs`, `var`, `layers`, `obsm` and `varm` are annotated by anndata to cover
every container it can hold, including sparse, backed and lazy ones. A
`DeseqDataSet` only ever holds in-memory dense counts and pandas metadata, so
those attributes are re-declared under `TYPE_CHECKING` with the narrower types
the class actually supports. `obsm` and `varm` mix DataFrames and ndarrays, so
they stay mappings to `Any` rather than take a union that would be wrong at half
the call sites.

The rest are call sites where `Series.values` is typed `ndarray |
ExtensionArray`; they now use the equivalent `to_numpy()`, which is annotated to
return an ndarray. The remaining handful are casts where anndata's union is
wider than what PyDESeq2 constructs and stores.

Everything here is annotations, `to_numpy()` swaps and casts, so runtime
behaviour is unchanged. mypy, ruff and the test suite pass.

Signed-off-by: Lukas Heumos <lukas.heumos@posteo.net>
@Zethson
Zethson merged commit e2bc0b4 into main Sep 6, 2026
10 checks passed
@Zethson
Zethson deleted the fix-anndata-013-typing branch September 6, 2026 18:40
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.

1 participant