From 36f88442209e74f0fcb63ec2aa3868b63f7dafb4 Mon Sep 17 00:00:00 2001 From: naveenarun Date: Wed, 21 Sep 2016 23:31:51 -0500 Subject: BUG: financial.pmt modifies input #8055 financial.pmt masked rate array in place, changing rate array. Changed to mask to a new array, preserving the original rate array. --- numpy/lib/financial.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'numpy/lib') diff --git a/numpy/lib/financial.py b/numpy/lib/financial.py index 931b0af56..95942da16 100644 --- a/numpy/lib/financial.py +++ b/numpy/lib/financial.py @@ -210,9 +210,10 @@ def pmt(rate, nper, pv, fv=0, when='end'): (rate, nper, pv, fv, when) = map(np.array, [rate, nper, pv, fv, when]) temp = (1 + rate)**nper mask = (rate == 0.0) - np.copyto(rate, 1.0, where=mask) - z = np.zeros(np.broadcast(rate, nper, pv, fv, when).shape) - fact = np.where(mask != z, nper + z, (1 + rate*when)*(temp - 1)/rate + z) + masked_rate = np.where(mask, 1.0, rate) + z = np.zeros(np.broadcast(masked_rate, nper, pv, fv, when).shape) + fact = np.where(mask != z, nper + z, + (1 + masked_rate*when)*(temp - 1)/masked_rate + z) return -(fv + pv*temp) / fact def nper(rate, pmt, pv, fv=0, when='end'): -- cgit v1.2.1