Skip to content

Commit 1656639

Browse files
authored
Merge pull request #94 from MashyBasker/test-docs-when-built-issue73
Add automated documentation testing when building
2 parents db5ab0a + 996adfb commit 1656639

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

.github/workflows/pythonpackage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ jobs:
2222
poetry install --with=test
2323
- name: Test with pytest
2424
run: |
25-
poetry run pytest
25+
poetry run pytest --doctest-modules

numpy_financial/_financial.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def fv(rate, nper, pmt, pv, when='end'):
146146
5% (annually) compounded monthly?
147147
148148
>>> npf.fv(0.05/12, 10*12, -100, -100)
149-
15692.928894335748
149+
15692.92889433575
150150
151151
By convention, the negative sign represents cash flow out (i.e. money not
152152
available today). Thus, saving $100 a month at 5% annual interest leads
@@ -157,7 +157,7 @@ def fv(rate, nper, pmt, pv, when='end'):
157157
158158
>>> a = np.array((0.05, 0.06, 0.07))/12
159159
>>> npf.fv(a, 10*12, -100, -100)
160-
array([ 15692.92889434, 16569.87435405, 17509.44688102]) # may vary
160+
array([15692.92889434, 16569.87435405, 17509.44688102])
161161
162162
"""
163163
when = _convert_when(when)
@@ -327,9 +327,9 @@ def nper(rate, pmt, pv, fv=0, when='end'):
327327
... 8000 : 9001 : 1000]))
328328
array([[[ 64.07334877, 74.06368256],
329329
[108.07548412, 127.99022654]],
330+
<BLANKLINE>
330331
[[ 66.12443902, 76.87897353],
331332
[114.70165583, 137.90124779]]])
332-
333333
"""
334334
when = _convert_when(when)
335335
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'):
592592
593593
>>> a = np.array((0.05, 0.04, 0.03))/12
594594
>>> npf.pv(a, 10*12, -100, 15692.93)
595-
array([ -100.00067132, -649.26771385, -1273.78633713]) # may vary
595+
array([ -100.00067132, -649.26771385, -1273.78633713])
596596
597597
So, to end up with the same $15692.93 under the same $100 per month
598598
"savings plan," for annual interest rates of 4% and 3%, one would
@@ -931,7 +931,7 @@ def npv(rate, values):
931931
net present value:
932932
933933
>>> rate, cashflows = 0.08, [-40_000, 5_000, 8_000, 12_000, 30_000]
934-
>>> npf.npv(rate, cashflows).round(5)
934+
>>> np.round(npf.npv(rate, cashflows), 5)
935935
3065.22267
936936
937937
It may be preferable to split the projected cashflow into an initial
@@ -1061,10 +1061,15 @@ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False):
10611061
Finally, let's explore the situation where all cash flows are positive,
10621062
and the `raise_exceptions` parameter is set to True.
10631063
1064-
>>> npf.mirr([100, 50, 60, 70], 0.10, 0.12, raise_exceptions=True)
1065-
NoRealSolutionError: No real solution exists for MIRR since all
1066-
cashflows are of the same sign.
1067-
1064+
>>> npf.mirr([
1065+
... 100, 50, 60, 70],
1066+
... 0.10, 0.12,
1067+
... raise_exceptions=True
1068+
... ) #doctest: +NORMALIZE_WHITESPACE
1069+
Traceback (most recent call last):
1070+
...
1071+
numpy_financial._financial.NoRealSolutionError:
1072+
No real solution exists for MIRR since all cashflows are of the same sign.
10681073
"""
10691074
values = np.asarray(values)
10701075
n = values.size

0 commit comments

Comments
 (0)