Skip to content

Commit 871ccb0

Browse files
Merge pull request #13 from WarrenWeckesser/removedispatch
MAINT: Remove array dispatch wrappers, and allow numpy back to 1.15.
2 parents b922ece + 9181553 commit 871ccb0

File tree

4 files changed

+4
-60
lines changed

4 files changed

+4
-60
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
max-parallel: 4
1111
matrix:
1212
python-version: [3.5, 3.6, 3.7]
13+
numpy-version: [1.15, 1.16, 1.17]
1314

1415
steps:
1516
- uses: actions/checkout@v1
@@ -20,7 +21,7 @@ jobs:
2021
- name: Install dependencies
2122
run: |
2223
python -m pip install --upgrade pip
23-
pip install -r requirements.txt
24+
pip install numpy==${{ matrix.numpy-version }}
2425
- name: Lint with flake8
2526
run: |
2627
pip install flake8

numpy_financial/_financial.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@
1313
from __future__ import division, absolute_import, print_function
1414

1515
from decimal import Decimal
16-
import functools
1716

1817
import numpy as np
19-
from numpy.core import overrides
20-
21-
22-
array_function_dispatch = functools.partial(
23-
overrides.array_function_dispatch, module='numpy')
2418

2519

2620
__all__ = ['fv', 'pmt', 'nper', 'ipmt', 'ppmt', 'pv', 'rate',
@@ -45,11 +39,6 @@ def _convert_when(when):
4539
return [_when_to_num[x] for x in when]
4640

4741

48-
def _fv_dispatcher(rate, nper, pmt, pv, when=None):
49-
return (rate, nper, pmt, pv)
50-
51-
52-
@array_function_dispatch(_fv_dispatcher)
5342
def fv(rate, nper, pmt, pv, when='end'):
5443
"""
5544
Compute the future value.
@@ -142,11 +131,6 @@ def fv(rate, nper, pmt, pv, when='end'):
142131
return -(pv*temp + pmt*fact)
143132

144133

145-
def _pmt_dispatcher(rate, nper, pv, fv=None, when=None):
146-
return (rate, nper, pv, fv)
147-
148-
149-
@array_function_dispatch(_pmt_dispatcher)
150134
def pmt(rate, nper, pv, fv=0, when='end'):
151135
"""
152136
Compute the payment against loan principal plus interest.
@@ -242,11 +226,6 @@ def pmt(rate, nper, pv, fv=0, when='end'):
242226
return -(fv + pv*temp) / fact
243227

244228

245-
def _nper_dispatcher(rate, pmt, pv, fv=None, when=None):
246-
return (rate, pmt, pv, fv)
247-
248-
249-
@array_function_dispatch(_nper_dispatcher)
250229
def nper(rate, pmt, pv, fv=0, when='end'):
251230
"""
252231
Compute the number of periodic payments.
@@ -319,11 +298,6 @@ def nper(rate, pmt, pv, fv=0, when='end'):
319298
return np.where(rate == 0, A, B)
320299

321300

322-
def _ipmt_dispatcher(rate, per, nper, pv, fv=None, when=None):
323-
return (rate, per, nper, pv, fv)
324-
325-
326-
@array_function_dispatch(_ipmt_dispatcher)
327301
def ipmt(rate, per, nper, pv, fv=0, when='end'):
328302
"""
329303
Compute the interest portion of a payment.
@@ -433,11 +407,6 @@ def _rbl(rate, per, pmt, pv, when):
433407
return fv(rate, (per - 1), pmt, pv, when)
434408

435409

436-
def _ppmt_dispatcher(rate, per, nper, pv, fv=None, when=None):
437-
return (rate, per, nper, pv, fv)
438-
439-
440-
@array_function_dispatch(_ppmt_dispatcher)
441410
def ppmt(rate, per, nper, pv, fv=0, when='end'):
442411
"""
443412
Compute the payment against loan principal.
@@ -467,11 +436,6 @@ def ppmt(rate, per, nper, pv, fv=0, when='end'):
467436
return total - ipmt(rate, per, nper, pv, fv, when)
468437

469438

470-
def _pv_dispatcher(rate, nper, pmt, fv=None, when=None):
471-
return (rate, nper, nper, pv, fv)
472-
473-
474-
@array_function_dispatch(_pv_dispatcher)
475439
def pv(rate, nper, pmt, fv=0, when='end'):
476440
"""
477441
Compute the present value.
@@ -586,19 +550,13 @@ def _g_div_gp(r, n, p, x, y, w):
586550
return g / gp
587551

588552

589-
def _rate_dispatcher(nper, pmt, pv, fv, when=None, guess=None, tol=None,
590-
maxiter=None):
591-
return (nper, pmt, pv, fv)
592-
593-
594553
# Use Newton's iteration until the change is less than 1e-6
595554
# for all values or a maximum of 100 iterations is reached.
596555
# Newton's rule is
597556
# r_{n+1} = r_{n} - g(r_n)/g'(r_n)
598557
# where
599558
# g(r) is the formula
600559
# g'(r) is the derivative with respect to r.
601-
@array_function_dispatch(_rate_dispatcher)
602560
def rate(nper, pmt, pv, fv, when='end', guess=None, tol=None, maxiter=100):
603561
"""
604562
Compute the rate of interest per period.
@@ -671,11 +629,6 @@ def rate(nper, pmt, pv, fv, when='end', guess=None, tol=None, maxiter=100):
671629
return rn
672630

673631

674-
def _irr_dispatcher(values):
675-
return (values,)
676-
677-
678-
@array_function_dispatch(_irr_dispatcher)
679632
def irr(values):
680633
"""
681634
Return the Internal Rate of Return (IRR).
@@ -756,11 +709,6 @@ def irr(values):
756709
return rate
757710

758711

759-
def _npv_dispatcher(rate, values):
760-
return (values,)
761-
762-
763-
@array_function_dispatch(_npv_dispatcher)
764712
def npv(rate, values):
765713
"""
766714
Returns the NPV (Net Present Value) of a cash flow series.
@@ -833,11 +781,6 @@ def npv(rate, values):
833781
return (values / (1+rate)**np.arange(0, len(values))).sum(axis=0)
834782

835783

836-
def _mirr_dispatcher(values, finance_rate, reinvest_rate):
837-
return (values,)
838-
839-
840-
@array_function_dispatch(_mirr_dispatcher)
841784
def mirr(values, finance_rate, reinvest_rate):
842785
"""
843786
Modified internal rate of return.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
numpy>=1.17
1+
numpy>=1.15

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_version():
5151
packages=find_packages(exclude=['doc']),
5252
author='Travis E. Oliphant et al.',
5353
license='BSD',
54-
install_requires=['numpy>=1.17'],
54+
install_requires=['numpy>=1.15'],
5555
python_requires='>=3.5',
5656
classifiers=CLASSIFIERS.splitlines(),
5757
project_urls={

0 commit comments

Comments
 (0)