BUG: ipmt not working with numpy==1.26.4 when using a pandas df as input.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Reproduce the example with numpy 1.26.4 and pandas 2.2.1, then inspect numpy_financial/_financial.py around ipmt, especially the failing np.where call. Compare the pandas-column inputs with the working reshaped-array example; done means ipmt accepts the reported DataFrame columns without raising and preserves the expected result.
Written by the indexing model from the issue text.
Description
Describe the issue:
Not sure if bug or feature request, but I used to be able to use pandas dataframe columns as input arrays to npf.ipmt(). With numpy 1.26.4 and pandas 2.2.1 that yields a ValueError. I think it might be due to a change in np.broadcast_arrays()
Reproduce the code example:
import pandas as pd
import numpy_financial as npf
import numpy as np
df = pd.DataFrame({'rate': [0.05, 0.07], 'periods':[np.array([1,2,3,4]), np.array([1,2,3,4])], 'pv': [10000, 12000], 'nper': [10,10]})
#ValueError
npf.ipmt(df['rate'], df['periods'], df['nper'], df['pv'])
#Works
npf.ipmt(np.array(df['rate'].tolist()).reshape(-1,1), np.array(df['periods'].tolist()), np.array(df['nper'].tolist()).reshape(-1,1), np.array(df['pv'].tolist()).reshape(-1,1))
Error message:
Traceback (most recent call last)
Cell In[4], line 2
1 df = pd.DataFrame({'rate': [0.05, 0.07], 'periods':[np.array([1,2,3,4]), np.array([1,2,3,4])], 'pv': [10000, 12000], 'nper': [10,10]})
----> 2 npf.ipmt(df['rate'], df['periods'], df['nper'], df['pv'])
File ~\.conda\envs\test\Lib\site-packages\numpy_financial\_financial.py:394, in ipmt(rate, per, nper, pv, fv, when)
392 try:
393 ipmt = np.where(when == 1, ipmt/(1 + rate), ipmt)
--> 394 ipmt = np.where(np.logical_and(when == 1, per == 1), 0, ipmt)
395 except IndexError:
396 pass
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Runtime information:
1.26.4
3.11.8 | packaged by Anaconda, Inc. | (main, Feb 26 2024, 21:34:05) [MSC v.1916 64 bit (AMD64)]
[{'numpy_version': '1.26.4',
'python': '3.11.8 | packaged by Anaconda, Inc. | (main, Feb 26 2024, '
'21:34:05) [MSC v.1916 64 bit (AMD64)]',
'uname': uname_result(system='Windows', node='xxx', release='10', version='10.0.19045', machine='AMD64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL']}}]
Context for the issue:
No response
- Dominant language
- Python
- Stars
- 416
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from numpy/numpy-financial
-
An integer `rate` truncates `fv` to an integer and makes `ipmt`/`ppmt` raisePossibly taken @naseweisssss claimed this 38 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
numpy/numpy-financial#166 ·
-
Add CUMPRINC and CUMIPMT functionsPossibly taken A pull request linked to this issue is open or already merged. Openenhancement sustain-2026
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
numpy/numpy-financial#38 · 6 comments · 1 reaction ·
-
BUG: integer power overflow in fv, pv and pmtPossibly taken @milliondreamsblog claimed this 19 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 65/100
numpy/numpy-financial#173 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
numpy/numpy-financial#131 · 1 comment ·
-
documentation sustain-2026
Difficulty 4/5 3-5 days Newbie friendliness 35/100
numpy/numpy-financial#130 · 8 comments ·
All issues in numpy/numpy-financial
Similar issues
-
todo
Difficulty 1/5 Under an hour Newbie friendliness 72/100
tonybaloney/CSnakes#864 ·
-
infra
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
libre-embedded/svgen#72 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Genesis-Embodied-AI/genesis-world#3950 ·
Maintainers usually reply within 1 day
-
accessibility
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day