Repository navigation
TYP: accept scalar-returning IRR selectors - #176
Open
pengpengyi92 wants to merge 1 commit into
Open
pengpengyi92 wants to merge 1 commit into
pengpengyi92 wants to merge 1 commit into
Conversation
jorenham
self-requested a review
November 12, 2026 09:35
This branch has not been deployed
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.
Problem
The public
irr(..., selection_logic=...)documentation says a custom selector receives a one-dimensional array of candidate rates and returns a number. The implementation assigns the selected value to one scalar entry inirr_results.However,
_SelectionFunccurrently requires anNDArray[np.float64]return, so mypy rejects valid selectors that returnfloat,np.float64ornp.float32. The default selector is also annotated as returning an array despite returning one indexed element.For example, this documented use is rejected:
Change
float | np.floating[Any]and the default selector result asnp.float64.typing_tests/irr_selection.py, included by the existing repository-widemypy .CI command. It covers the default selector, three supported scalar-returning callbacks and rejection of an array-valued callback. The last case uses a narrowtype: ignore[arg-type]; the existingwarn_unused_ignoressetting makes the fixture fail if array selectors become accepted again.Verification
Base:
031ed55d322b7aad57311b9d63b589c79df942a1.python -m mypy --no-incremental --cache-dir <temporary-path> .: success, 5 source files checked.python -m pyright --pythonpath <isolated-python> --pythonversion 3.13 numpy_financial typing_tests/irr_selection.py: 0 errors / 0 warnings.git diff --check: pass on the two changed files.AI assistance: OpenAI Codex assisted with reproduction, the two annotation changes and the static contract fixture.