Repository navigation
BUG: take the fv result dtype from all inputs, not just rate - #167
Closed
kritagyadubey wants to merge 1 commit into
Closed
kritagyadubey wants to merge 1 commit into
kritagyadubey wants to merge 1 commit into
Conversation
An integer rate gave an integer output buffer, so fractional results were truncated and ipmt/ppmt raised ValueError when they tried to store NaN in the remaining-balance array.
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.
Fixes #166
Problem
fvsizes and types its output buffer fromratealone (np.empty_like(rate)), so an integer rate gives an integer buffer and the float result is truncated toward zero:npf.fv(0, 12, -100.5, -1000.25)returns2206instead of2206.25.ipmtandppmtare affected through_rbl, which callsfv. The remaining-balance array comes back integer typed, and_value_likecannot store NaN in it, so they raiseValueError: cannot convert float NaN to integerbefore any arithmetic happens:This only takes an extra float (
0.0instead of0) to avoid, which is easy to miss for the common case of a 0% loan.Change
Derive the dtype from all the inputs when allocating the
fvoutput buffer:This matches the promotion the rest of the module already gets from arithmetic.
pmt,ppmtandpvall return float64 for the same integer inputs, sofvwas the only function affected. Inputs that are already float are unchanged, sinceresult_typetreats the1.0literal as a weak scalar, andDecimalinputs still produce an object array.Testing
Run on Python 3.14.7, numpy 2.5.4, Windows:
spin test -- --doctest-modules: 122 passed, including three new regression tests (TestFv::test_gh_166,TestIpmt::test_gh_166,TestPpmt::test_gh_166). All three fail without the change to_financial.py.ruff check numpy_financial/ benchmarks/,mypy --no-incremental .andpyright(the checks inspin lint): no findings.