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

BUG: ipmt not working with numpy==1.26.4 when using a pandas df as input. #105

Open
erikgrenestam opened this issue Mar 19, 2024 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@erikgrenestam
Copy link

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

@Kai-Striega
Copy link
Member

I'll take a look into this over the weekend. I agree that you should be able to use pandas with NumPy financial.

@Kai-Striega Kai-Striega added bug Something isn't working help wanted Extra attention is needed labels Mar 21, 2024
@Kai-Striega Kai-Striega added this to the 2.0 milestone Mar 21, 2024
@Kai-Striega
Copy link
Member

@erikgrenestam I can reproduce this on the main branch, I've marked it as a bug and will try to fix it by the time we get to the 2.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants