Repository navigation
Fix type errors surfaced by anndata 0.13 - #456
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.valuesforto_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.