Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

An integer `rate` truncates `fv` to an integer and makes `ipmt`/`ppmt` raise

Aperta Adatta ai principianti
#166 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

  • #167 di @kritagyadubey — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
numpy, python
Ambito
backend

Direzione di ricerca

Inizia leggendo fv in numpy_financial/_financial.py, dove l’issue indica fv_array = np.empty_like(rate) come causa del troncamento degli interi. Controlla come _rbl e _value_like usano quel risultato in ipmt e ppmt, poi esegui i test esistenti e riproduci i quattro esempi nell’issue. Il lavoro è concluso quando un rate=0 intero restituisce i risultati in virgola mobile indicati per fv, ipmt e ppmt, e i test esistenti continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the issue:

With rate given as an integer — the natural way to write a 0% loan — fv returns a truncated integer, and ipmt / ppmt raise ValueError. With rate=0.0 everything is right.

Where: in fv, fv_array = np.empty_like(rate) sizes and types the output buffer from rate alone, so an integer rate gives an int64 buffer and every float result written into it is truncated toward zero (the line dates from 8c7e6e1, 2019). ipmt builds its remaining-balance buffer through fv (_rbl), inherits the int64 dtype, and _value_like then tries to store NaN in it, which raises even when no element needs the NaN.

Expected: the output dtype follows all the inputs, e.g. np.result_type(rate, nper, pmt, pv, 1.0), so an integer rate behaves like a float one. With that one change fv gives 2206.25, ipmt -0.0 and ppmt -100.0 below, and the 110 tests still pass. None of the existing tests catches this: they all pass a float rate.

Reproduce the code example:
import numpy_financial as npf

print(npf.fv(0, 12, -100.5, -1000.25))    # 2206      expected 2206.25 = -(pv + pmt*nper) at rate 0
print(npf.fv(0.0, 12, -100.5, -1000.25))  # 2206.25
print(npf.ipmt(0, 1, 12, 1200))           # ValueError, expected 0.0 (no interest at 0%)
print(npf.ppmt(0, 1, 12, 1200))           # ValueError, expected -100.0
Error message:
Traceback (most recent call last):
  ...
  File ".../numpy_financial/_financial.py", in ipmt
ValueError: cannot convert float NaN to integer
Runtime information:

Python 3.13.13, numpy 2.5.4, numpy-financial 1.2.0.dev0 at 90e1ed1 (editable build), macOS 27.0.1 arm64.

Context for the issue:

Found by Verdict, an AI QA agent (Claude Opus); I re-ran it by hand on a fresh clone with the snippet above. The same pass flagged irr returning -1.0 instead of nan for cash flows with no sign change that end in zeros (irr([100, 50, 0]), even with raise_exceptions=True); I can file that separately if useful. It also hit the rate results below -100% that #158 fixes.

Lingua principale
Python
Stelle
414
Fork
106
Merge medio
1g 3h
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di numpy/numpy-financial

Tutte le issue di numpy/numpy-financial

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.