Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

financial.pmt modifies input #8055

Closed
jblackma opened this issue Sep 16, 2016 · 3 comments
Closed

financial.pmt modifies input #8055

jblackma opened this issue Sep 16, 2016 · 3 comments
Labels

Comments

@jblackma
Copy link

Whenever an array of rates is passed into np.pmt, all zeros in the array are converted to 1:

>>> import numpy as np
>>> print np.__version__
1.11.0
>>> rates = np.array([0., 0.5])
>>> print np.pmt(rates, 5, 1.0)
[-0.2        -0.57582938]
>>> print rates
[ 1.   0.5]

This is done internally in np.pmt to avoid dividing by zero, but it should be done in a way that does not modify the input arrays.

@jaimefrio
Copy link
Member

Thanks for reporting! It's happening here:

https://github.com/numpy/numpy/blob/master/numpy/lib/financial.py#L213

Either rate should be made a copy of the original rate, e.g. by doing rate = np.array(rate) instead of the current rate = np.asarray(rate), or the line I marked above should create a new array, e.g. rate = np.where(mask, 1.0, rate).

You are welcome to send a PR, and I'll be more than happy to guide you through the motions of doing so, just ask!

Otherwise I don't think any of the maintainers is going to spend much time with the financial module (unless it is to remove it!).

KhaledTo added a commit to KhaledTo/numpy that referenced this issue Sep 19, 2016
charris added a commit that referenced this issue Sep 19, 2016
BUG : financial.pmt modifies input (issue #8055)
hodgka pushed a commit to hodgka/numpy that referenced this issue Sep 23, 2016
financial.pmt masked rate array in place, changing rate array.
Changed to mask to a new array, preserving the original rate array.
@hodgka
Copy link

hodgka commented Sep 23, 2016

Made a pull request here #8087

hodgka pushed a commit to hodgka/numpy that referenced this issue Sep 23, 2016
financial.pmt masked rate array in place, changing rate array.
Changed to mask to a new array, preserving the original rate array.
charris added a commit that referenced this issue Sep 23, 2016
BUG: financial.pmt modifies input #8055
@charris
Copy link
Member

charris commented Dec 4, 2016

Fixed by #8061.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants