Repository navigation
Annotate the pmcid arrays as ndarray, not Sequence[int] - #62
Merged
Merged
Conversation
`make test_mypy` fails on main under numpy >= 2.1:
_vectorization.py:200: error: Incompatible return value type
(got "tuple[ndarray[tuple[Any, ...], dtype[Any]], dict[str, Any], Any]",
expected "tuple[Sequence[int], dict[str, Any], Any]")
`_extract_word_counts` returns `np.concatenate(...)`, which is an ndarray, while
the signature promises `Sequence[int]`. Older numpy stubs let an ndarray satisfy
Sequence[int]; from 2.1 the shape-parameterised `ndarray[tuple[Any, ...],
dtype[Any]]` no longer does, so the CI matrix's py313-latest-deps job started
failing while py310-min-deps still passes.
`_vectorize_articles` has the same mistake one level down -- it returns
`articles["pmcid"].values` under the same `Sequence[int]` annotation. mypy cannot
see it because DataFrame.values is Any without pandas stubs, so it would surface
the moment those are added. Fixed both.
Annotations only; no behaviour change.
Verified under both extremes: with numpy 2.5.3, mypy goes from the error above to
"Success: no issues found"; with numpy 1.25.2 the file is clean before and after.
The module still imports, and the annotation resolves to a real ndarray type.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
make test_mypycurrently fails onmain:_extract_word_countsreturnsnp.concatenate(...), an ndarray, while itssignature promises
Sequence[int]. Older numpy stubs allowed an ndarray tosatisfy
Sequence[int]; from numpy 2.1 the shape-parameterisedndarray[tuple[Any, ...], dtype[Any]]no longer does. That is why the failureappeared without any change to this file — the
py313-latest-depsleg of thematrix now resolves a numpy new enough to reject it, while
py310-min-depsstill passes.
_vectorize_articleshas the same mistake one level down: it returnsarticles["pmcid"].valuesunder the sameSequence[int]annotation. mypy cannotcurrently see it, because
DataFrame.valuesisAnywithout pandas stubs, but itwould surface as soon as those are installed. Both are fixed here.
Annotations only — no behaviour change.
Verification
Reproduced the CI failure locally in a clean venv with numpy 2.5.3 and mypy 2.3.1,
then confirmed the fix under both extremes:
Success: no issues foundThe module still imports and the annotation resolves to a real
numpy.ndarraytype at runtime.
🤖 Generated with Claude Code