Fix mypy return-type error in _mreg_distances FACTOR branch - #115
Merged
Conversation
np.mean(..., axis=2) is typed as float64 | ndarray by the numpy stubs even though axis=2 always yields an array. Narrow it with the same cast(NDArray[np.float64], ...) idiom already used elsewhere in the file, making mypy fully clean (47 files, no issues). Pure type narrowing; no runtime change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019F6ZjcfXSxZWGMuSmQGmLN
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.
Summary
Closes the one remaining mypy error so the type-check is fully green.
_mreg_distancesreturnednp.mean(rpm_x[None, :, :] != xtest[:, None, :], axis=2, dtype=np.float64)in theFACTORbranch. numpy's stubs typenp.mean(...)asfloat64 | ndarrayeven though passingaxis=2always yields an array, so mypy flagged an incompatible return value against the declaredNDArray[np.float64].Narrowed the result with
cast(NDArray[np.float64], ...)— the same idiom already used elsewhere in this module (e.g._reg_engine.py:400). This is a pure type narrowing with no runtime change.Verification
mypy src/nns→Success: no issues found in 47 source files(was 1 error)ruff check→ cleantests/parity/test_multivariate_regression.py,tests/parity/test_regression.py: 323 passed)🤖 Generated with Claude Code
Generated by Claude Code