diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2020-08-22 19:48:35 -0400 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2020-08-22 20:16:58 -0400 |
commit | adccacf32ea8c159b2397a6053f4b97543ec08a7 (patch) | |
tree | 2c2b2261898a651005d0f1015d5c9961b77beb0f /numpy/__init__.py | |
parent | 97f9fcb599fec377f35be647afdc2d5c2c6ba1f9 (diff) | |
download | numpy-adccacf32ea8c159b2397a6053f4b97543ec08a7.tar.gz |
MAINT: lib: Change handling of the expired financial functions.
In a previous commit, the expired financial functions were removed
from NumPy, and code was added to __init__.py using the module
__getattr__ to raise a customized AttributeError on any attempt to
reference the expired names in the numpy namespace.
That change broke released versions astropy, which has code that
imports the financial functions. astropy never calls the functions,
so they never saw the deprecation warnings that have been in place
since numpy 1.18. This means that attempting to use a released
version of astropy with numpy 1.20 will cause astropy to crash
with the custom AttributeError.
In this commit, instead of raising an exception when one of the
expired names is referenced, a warning is generated. If the
function is *called*, an exception is raised.
Diffstat (limited to 'numpy/__init__.py')
-rw-r--r-- | numpy/__init__.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index c594928ce..8dc805379 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -215,9 +215,8 @@ 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__ = { @@ -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] 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: |