diff options
Diffstat (limited to 'numpy/__init__.py')
-rw-r--r-- | numpy/__init__.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index c594928ce..41c3dc42d 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -215,12 +215,11 @@ else: 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. + # attempts to access these names in the numpy namespace will trigger + # a warning, and calling the function will raise an exception. _financial_names = ['fv', 'ipmt', 'irr', 'mirr', 'nper', 'npv', 'pmt', 'ppmt', 'pv', 'rate'] - __expired_attrs__ = { + __expired_functions__ = { 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: ' @@ -241,13 +240,19 @@ 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 + # Warn for expired attributes, and return a dummy function + # that always raises an exception. try: - msg = __expired_attrs__[attr] + msg = __expired_functions__[attr] except KeyError: pass else: - raise AttributeError(msg) + warnings.warn(msg, RuntimeWarning) + + def _expired(*args, **kwds): + raise RuntimeError(msg) + + return _expired # Emit warnings for deprecated attributes try: |