Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#166 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

@kritagyadubey ya está trabajando en esto.

Desde el 17/10/2026.

  • #167 de @kritagyadubey — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
numpy, python
Área
backend

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

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de numpy/numpy-financial

Todos los issues de numpy/numpy-financial

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.