From 2153b600befb8943271bcdfcbf4280d7104fbe1f Mon Sep 17 00:00:00 2001 From: MashyBasker Date: Wed, 6 Dec 2023 01:34:32 +0530 Subject: [PATCH 1/8] [TST/CI] Add automated documentation testing when building --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 5d32bea..f3d6002 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -22,4 +22,4 @@ jobs: poetry install --with=test - name: Test with pytest run: | - poetry run pytest + poetry run pytest --doctest-modules From 38e6819bfd812180862a54fd3e5875e5da06c792 Mon Sep 17 00:00:00 2001 From: MashyBasker Date: Sat, 9 Dec 2023 15:39:50 +0530 Subject: [PATCH 2/8] [DOC] Fix doctest failure issue. Resolves issue #94 --- numpy_financial/_financial.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index 50728d8..719a2c9 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -115,7 +115,7 @@ def fv(rate, nper, pmt, pv, when='end'): 5% (annually) compounded monthly? >>> npf.fv(0.05/12, 10*12, -100, -100) - 15692.928894335748 + 15692.92889433575 By convention, the negative sign represents cash flow out (i.e. money not available today). Thus, saving $100 a month at 5% annual interest leads @@ -126,7 +126,7 @@ def fv(rate, nper, pmt, pv, when='end'): >>> a = np.array((0.05, 0.06, 0.07))/12 >>> npf.fv(a, 10*12, -100, -100) - array([ 15692.92889434, 16569.87435405, 17509.44688102]) # may vary + array([15692.92889434, 16569.87435405, 17509.44688102]) """ when = _convert_when(when) @@ -296,9 +296,9 @@ def nper(rate, pmt, pv, fv=0, when='end'): ... 8000 : 9001 : 1000])) array([[[ 64.07334877, 74.06368256], [108.07548412, 127.99022654]], + [[ 66.12443902, 76.87897353], [114.70165583, 137.90124779]]]) - """ when = _convert_when(when) rate, pmt, pv, fv, when = np.broadcast_arrays(rate, pmt, pv, fv, when) @@ -561,7 +561,7 @@ def pv(rate, nper, pmt, fv=0, when='end'): >>> a = np.array((0.05, 0.04, 0.03))/12 >>> npf.pv(a, 10*12, -100, 15692.93) - array([ -100.00067132, -649.26771385, -1273.78633713]) # may vary + array([ -100.00067132, -649.26771385, -1273.78633713]) So, to end up with the same $15692.93 under the same $100 per month "savings plan," for annual interest rates of 4% and 3%, one would @@ -878,7 +878,7 @@ def npv(rate, values): net present value: >>> rate, cashflows = 0.08, [-40_000, 5_000, 8_000, 12_000, 30_000] - >>> npf.npv(rate, cashflows).round(5) + >>> round(npf.npv(rate, cashflows), 5) 3065.22267 It may be preferable to split the projected cashflow into an initial @@ -967,9 +967,9 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False): and the `raise_exceptions` parameter is set to True. >>> npf.mirr([100, 50, 60, 70], 0.10, 0.12, raise_exceptions=True) - NoRealSolutionError: No real solution exists for MIRR since all - cashflows are of the same sign. - + Traceback (most recent call last): + ... + numpy_financial._financial.NoRealSolutionError: No real solution exists for MIRR since all cashflows are of the same sign. """ values = np.asarray(values) n = values.size From 3311612dc27bf4d7df10e7cc5b7222bf51113728 Mon Sep 17 00:00:00 2001 From: Maharshi Basu <84385565+MashyBasker@users.noreply.github.com> Date: Sat, 9 Dec 2023 15:55:16 +0530 Subject: [PATCH 3/8] Change round() to np.round() --- numpy_financial/_financial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index 719a2c9..eb3f13d 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -878,7 +878,7 @@ def npv(rate, values): net present value: >>> rate, cashflows = 0.08, [-40_000, 5_000, 8_000, 12_000, 30_000] - >>> round(npf.npv(rate, cashflows), 5) + >>> np.round(npf.npv(rate, cashflows), 5) 3065.22267 It may be preferable to split the projected cashflow into an initial From 8fa019f83a45fe2668e244ff8bec811efdaf684e Mon Sep 17 00:00:00 2001 From: MashyBasker Date: Wed, 6 Dec 2023 01:34:32 +0530 Subject: [PATCH 4/8] [TST/CI] Add automated documentation testing when building --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index ff67b07..1eb0d4a 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -22,4 +22,4 @@ jobs: poetry install --with=test - name: Test with pytest run: | - poetry run pytest + poetry run pytest --doctest-modules From d95c032396b71119236248832c904e3d6020764c Mon Sep 17 00:00:00 2001 From: MashyBasker Date: Sat, 9 Dec 2023 15:39:50 +0530 Subject: [PATCH 5/8] [DOC] Fix doctest failure issue. Resolves issue #94 --- numpy_financial/_financial.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index 26e31fe..dd2a11d 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -146,7 +146,7 @@ def fv(rate, nper, pmt, pv, when='end'): 5% (annually) compounded monthly? >>> npf.fv(0.05/12, 10*12, -100, -100) - 15692.928894335748 + 15692.92889433575 By convention, the negative sign represents cash flow out (i.e. money not available today). Thus, saving $100 a month at 5% annual interest leads @@ -157,7 +157,7 @@ def fv(rate, nper, pmt, pv, when='end'): >>> a = np.array((0.05, 0.06, 0.07))/12 >>> npf.fv(a, 10*12, -100, -100) - array([ 15692.92889434, 16569.87435405, 17509.44688102]) # may vary + array([15692.92889434, 16569.87435405, 17509.44688102]) """ when = _convert_when(when) @@ -327,9 +327,9 @@ def nper(rate, pmt, pv, fv=0, when='end'): ... 8000 : 9001 : 1000])) array([[[ 64.07334877, 74.06368256], [108.07548412, 127.99022654]], + [[ 66.12443902, 76.87897353], [114.70165583, 137.90124779]]]) - """ when = _convert_when(when) rate, pmt, pv, fv, when = np.broadcast_arrays(rate, pmt, pv, fv, when) @@ -592,7 +592,7 @@ def pv(rate, nper, pmt, fv=0, when='end'): >>> a = np.array((0.05, 0.04, 0.03))/12 >>> npf.pv(a, 10*12, -100, 15692.93) - array([ -100.00067132, -649.26771385, -1273.78633713]) # may vary + array([ -100.00067132, -649.26771385, -1273.78633713]) So, to end up with the same $15692.93 under the same $100 per month "savings plan," for annual interest rates of 4% and 3%, one would @@ -931,7 +931,7 @@ def npv(rate, values): net present value: >>> rate, cashflows = 0.08, [-40_000, 5_000, 8_000, 12_000, 30_000] - >>> npf.npv(rate, cashflows).round(5) + >>> round(npf.npv(rate, cashflows), 5) 3065.22267 It may be preferable to split the projected cashflow into an initial @@ -1062,9 +1062,9 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False): and the `raise_exceptions` parameter is set to True. >>> npf.mirr([100, 50, 60, 70], 0.10, 0.12, raise_exceptions=True) - NoRealSolutionError: No real solution exists for MIRR since all - cashflows are of the same sign. - + Traceback (most recent call last): + ... + numpy_financial._financial.NoRealSolutionError: No real solution exists for MIRR since all cashflows are of the same sign. """ values = np.asarray(values) n = values.size From 7737d4c07017a7ecf870931cc8f1fa1cbf822ffc Mon Sep 17 00:00:00 2001 From: MashyBasker Date: Sun, 10 Dec 2023 09:10:09 +0530 Subject: [PATCH 6/8] Fix linting issue in doctests for PR 94 --- numpy_financial/_financial.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index dd2a11d..d8b8621 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -1061,10 +1061,15 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False): Finally, let's explore the situation where all cash flows are positive, and the `raise_exceptions` parameter is set to True. - >>> npf.mirr([100, 50, 60, 70], 0.10, 0.12, raise_exceptions=True) + >>> npf.mirr([ + ... 100, 50, 60, 70], + ... 0.10, 0.12, + ... raise_exceptions=True + ... ) #doctest: +NORMALIZE_WHITESPACE Traceback (most recent call last): ... - numpy_financial._financial.NoRealSolutionError: No real solution exists for MIRR since all cashflows are of the same sign. + numpy_financial._financial.NoRealSolutionError: No real solution exists for MIRR since + all cashflows are of the same sign. """ values = np.asarray(values) n = values.size From 6e8af4ce74721ea72aa45392d657e7d802b3bb35 Mon Sep 17 00:00:00 2001 From: MashyBasker Date: Sun, 10 Dec 2023 09:40:53 +0530 Subject: [PATCH 7/8] Fix linting errors and build errors --- numpy_financial/_financial.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index 46dc065..67cbf85 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -931,11 +931,7 @@ def npv(rate, values): net present value: >>> rate, cashflows = 0.08, [-40_000, 5_000, 8_000, 12_000, 30_000] -<<<<<<< HEAD - >>> round(npf.npv(rate, cashflows), 5) -======= >>> np.round(npf.npv(rate, cashflows), 5) ->>>>>>> 3311612dc27bf4d7df10e7cc5b7222bf51113728 3065.22267 It may be preferable to split the projected cashflow into an initial @@ -1065,7 +1061,6 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False): Finally, let's explore the situation where all cash flows are positive, and the `raise_exceptions` parameter is set to True. -<<<<<<< HEAD >>> npf.mirr([ ... 100, 50, 60, 70], ... 0.10, 0.12, @@ -1075,12 +1070,6 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False): ... numpy_financial._financial.NoRealSolutionError: No real solution exists for MIRR since all cashflows are of the same sign. -======= - >>> npf.mirr([100, 50, 60, 70], 0.10, 0.12, raise_exceptions=True) - Traceback (most recent call last): - ... - numpy_financial._financial.NoRealSolutionError: No real solution exists for MIRR since all cashflows are of the same sign. ->>>>>>> 3311612dc27bf4d7df10e7cc5b7222bf51113728 """ values = np.asarray(values) n = values.size From 996adfbf75da3053460ad402f76793dc0e972cbf Mon Sep 17 00:00:00 2001 From: MashyBasker Date: Sun, 10 Dec 2023 09:53:42 +0530 Subject: [PATCH 8/8] Fix line too long error --- numpy_financial/_financial.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numpy_financial/_financial.py b/numpy_financial/_financial.py index 67cbf85..033495d 100644 --- a/numpy_financial/_financial.py +++ b/numpy_financial/_financial.py @@ -1068,8 +1068,8 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False): ... ) #doctest: +NORMALIZE_WHITESPACE Traceback (most recent call last): ... - numpy_financial._financial.NoRealSolutionError: No real solution exists for MIRR since - all cashflows are of the same sign. + numpy_financial._financial.NoRealSolutionError: + No real solution exists for MIRR since all cashflows are of the same sign. """ values = np.asarray(values) n = values.size