An integer `rate` truncates `fv` to an integer and makes `ipmt`/`ppmt` raise
Los mantenedores suelen responder en 3 días
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 68/100
Línea de trabajo
Empieza leyendo fv en numpy_financial/_financial.py, donde el issue identifica fv_array = np.empty_like(rate) como la causa del truncamiento a enteros. Comprueba cómo _rbl y _value_like usan ese resultado en ipmt y ppmt; después ejecuta las pruebas existentes y reproduce los cuatro ejemplos del issue. Se considera terminado cuando un rate=0 entero produce los resultados de coma flotante indicados para fv, ipmt y ppmt, y las pruebas existentes siguen pasando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 412
- Forks
- 105
- Merge medio
- 1 d 3 h
- PR fusionados (30 d)
- 1
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de numpy/numpy-financial
-
DOC: `conda activate` command in the dev docs does not match the environment name in `environment.yml`Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
numpy/numpy-financial#168 ·
Los mantenedores suelen responder en 3 días
-
Add CUMPRINC and CUMIPMT functionsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertoenhancement sustain-2026
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
numpy/numpy-financial#38 · 6 comentarios · 1 reacción ·
Los mantenedores suelen responder en 3 días
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
numpy/numpy-financial#131 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
DOC: Clarify the sign convention for fv in pmt documentation.Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertodocumentation sustain-2026
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
numpy/numpy-financial#130 · 8 comentarios ·
Los mantenedores suelen responder en 3 días
-
BUG: rate returning incorrect valuePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
numpy/numpy-financial#126 · 4 comentarios ·
Los mantenedores suelen responder en 3 días
Todos los issues de numpy/numpy-financial
Issues similares
-
bug Size: XS
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
oposs/repo-infra#93 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
Graphify-Labs/graphify#4546 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
521xueweihan/HelloGitHub#4025 ·