summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/lib/financial.py2
-rw-r--r--numpy/lib/tests/test_financial.py7
2 files changed, 7 insertions, 2 deletions
diff --git a/numpy/lib/financial.py b/numpy/lib/financial.py
index c42424da1..f1a1a4287 100644
--- a/numpy/lib/financial.py
+++ b/numpy/lib/financial.py
@@ -651,7 +651,7 @@ def irr(values):
"""
res = np.roots(values[::-1])
mask = (res.imag == 0) & (res.real > 0)
- if res.size == 0:
+ if not mask.any():
return np.nan
res = res[mask].real
# NPV(rate) = 0 can have more than one solution so we return
diff --git a/numpy/lib/tests/test_financial.py b/numpy/lib/tests/test_financial.py
index baa785424..cc8ba55e5 100644
--- a/numpy/lib/tests/test_financial.py
+++ b/numpy/lib/tests/test_financial.py
@@ -3,7 +3,7 @@ from __future__ import division, absolute_import, print_function
import numpy as np
from numpy.testing import (
run_module_suite, TestCase, assert_, assert_almost_equal,
- assert_allclose
+ assert_allclose, assert_equal
)
@@ -26,6 +26,11 @@ class TestFinancial(TestCase):
v = [-5, 10.5, 1, -8, 1]
assert_almost_equal(np.irr(v), 0.0886, 2)
+ # Test that if there is no solution then np.irr returns nan
+ # Fixes gh-6744
+ v = [-1, -2, -3]
+ assert_equal(np.irr(v), np.nan)
+
def test_pv(self):
assert_almost_equal(np.pv(0.07, 20, 12000, 0), -127128.17, 2)