diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2020-08-12 20:41:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-12 19:41:23 -0500 |
commit | b4fd7a79bc55f17f301d219492528e6f5f40c6f0 (patch) | |
tree | 244ffaa0968549d474580eaaf17dc4f97aedc42e /numpy/__init__.py | |
parent | 2b54640ad50bbbfecfb4c9cc8c9dd9c161f6a52e (diff) | |
download | numpy-b4fd7a79bc55f17f301d219492528e6f5f40c6f0.tar.gz |
DEP: lib: Remove the deprecated financial functions. (#17067)
As explained in NEP 32, the financial functions are to be removed
from version 1.20.
They are now replaced with module level `__getattr__` to give a useful
error message for those surprised by the `AttributeError`.
This only works for Python 3.7+, but it is expected that by the 1.20 release
Python 3.6 will not be supported.
Diffstat (limited to 'numpy/__init__.py')
-rw-r--r-- | numpy/__init__.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index 6c4ac98bd..c594928ce 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -214,6 +214,19 @@ else: __all__.remove('Arrayterator') del Arrayterator + # These names were removed in NumPy 1.20. For at least one release, + # attempts to access these names in the numpy namespace will have an + # error message that refers to NEP 32 and points to the numpy_financial + # library. + _financial_names = ['fv', 'ipmt', 'irr', 'mirr', 'nper', 'npv', 'pmt', + 'ppmt', 'pv', 'rate'] + __expired_attrs__ = { + name: (f'In accordance with NEP 32, the function {name} was removed ' + 'from NumPy version 1.20. A replacement for this function ' + 'is available in the numpy_financial library: ' + 'https://pypi.org/project/numpy-financial') + for name in _financial_names} + # Filter out Cython harmless warnings warnings.filterwarnings("ignore", message="numpy.dtype size changed") warnings.filterwarnings("ignore", message="numpy.ufunc size changed") @@ -228,6 +241,14 @@ else: # module level getattr is only supported in 3.7 onwards # https://www.python.org/dev/peps/pep-0562/ def __getattr__(attr): + # Raise AttributeError for expired attributes + try: + msg = __expired_attrs__[attr] + except KeyError: + pass + else: + raise AttributeError(msg) + # Emit warnings for deprecated attributes try: val, msg = __deprecated_attrs__[attr] |