You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An integer rate truncates fv to an integer and makes ipmt/ppmt raise #166
With rate given as an integer — the natural way to write a 0% loan — fv returns a truncated integer, and ipmt / ppmt raise ValueError. With rate=0.0 everything is right.
Where: in fv, fv_array = np.empty_like(rate) sizes and types the output buffer from rate alone, so an integer rate gives an int64 buffer and every float result written into it is truncated toward zero (the line dates from 8c7e6e1, 2019). ipmt builds its remaining-balance buffer through fv (_rbl), inherits the int64 dtype, and _value_like then tries to store NaN in it, which raises even when no element needs the NaN.
Expected: the output dtype follows all the inputs, e.g. np.result_type(rate, nper, pmt, pv, 1.0), so an integer rate behaves like a float one. With that one change fv gives 2206.25, ipmt -0.0 and ppmt -100.0 below, and the 110 tests still pass. None of the existing tests catches this: they all pass a float rate.
Found by Verdict, an AI QA agent (Claude Opus); I re-ran it by hand on a fresh clone with the snippet above. The same pass flagged irr returning -1.0 instead of nan for cash flows with no sign change that end in zeros (irr([100, 50, 0]), even with raise_exceptions=True); I can file that separately if useful. It also hit the rate results below -100% that #158 fixes.
Activity