Repository navigation
TST: expand test coverage with edge cases and identity checks (#58) - #140
MukundaKatta wants to merge 1 commit into
Conversation
Adds numpy_financial/tests/test_coverage_expansion.py with 83 new tests focused on: * zero-rate edge cases for fv, pmt, pv, nper * error paths (npv shape errors, mirr size mismatch, irr no real solution, rate iterations exceeded on arrays) * vectorized vs scalar parity for fv, pmt, pv * analytical round-trip identities (pmt = ppmt + ipmt, npv(irr(x), x) = 0, fv/pv inversion) * _convert_when alias dispatch and ndarray pass-through * _irr_default_selection branches and custom selection_logic Coverage of numpy_financial/_financial.py rises from 97% to 99%. Refs numpygh-58.
|
One policy question raised by A cash-flow example makes the distinction visible: import numpy_financial as npf
npf.irr([-100, 207, -106.4])
# 0.11999999999999855Both -5% and 12% make NPV zero here. The returned 12% is valid, but it is not the root closest to zero. Is that preference intended? If so, could the test comment and the selection-policy documentation state it directly? The implementation comment also mentions comparing cash flows, although I checked this against 1.1.0 and the financial module at this PR's head, |
Summary
Refs #58. Expands test coverage with edge cases and identity checks. No library code touched.
Coverage delta
numpy_financial/_financial.py: 97% (6 missing) → 99% (2 missing). The 2 remaining lines are unreachable defensive branches.What's added
83 new test cases in 8 classes covering:
fv/pmt/pv/nper, infinite cashflows, scalar/0-d/array shapes, negative ratesnpvinvalid shape,mirrsize mismatch (both raise + nan-return),irrno-real-solution,rateiterations-exceeded array pathfv,pmt,pvpmt = ppmt + ipmt,npv(irr(x), x) = 0,fv/pvinverse relations_convert_whenalias coverage (9 aliases + ndarray pass-through + KeyError)_irr_default_selectionmixed-sign / same-sign / all-negative branches + customselection_logicinjectionFiles changed
numpy_financial/tests/test_coverage_expansion.py(new, 550 lines, 83 tests)Test plan
ruff formatandruff checkclean on the new file