Skip to content

Conversation

@WarrenWeckesser
Copy link
Member

As explained in NEP 32, the financial functions are to be removed
from version 1.20.

@WarrenWeckesser WarrenWeckesser added component: numpy.lib 07 - Deprecation 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes component: numpy.lib.financial and removed 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes labels Aug 11, 2020
@seberg
Copy link
Member

seberg commented Aug 12, 2020

Happy to do this. We could also go through an additional VisibleDeprecationWarning cycle, but I suppose, we always have the option to revert the removal and do that instead...

Lets sign it off in the meeting today (technically, its already accepted so...).

@eric-wieser
Copy link
Member

Another option: replace the functions with stubs that just raise RuntimeError, just so that users get a better message than AttributeError

@seberg
Copy link
Member

seberg commented Aug 12, 2020

Hmm, the error idea is indeed maybe a bit gentler and only leaves like 50 lines of code probably. Too bad we can't put it directly on numpy.financial yet.

Comment on lines 247 to 248
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit for consistency with the code below:

Suggested change
raise AttributeError(msg)
except KeyError:
pass
except KeyError:
pass
else:
raise AttributeError(msg)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in an update.

Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking on using __getattr__. Maybe worth a test for this - checking that NEP 32 appears in the error message for just np.fv would be plenty.

@WarrenWeckesser
Copy link
Member Author

More than one person suggested using the module __getattr__ function to handle the error message. I pushed a commit that implements this by adding __expired_attributes__ in numpy/__init__.py. It is handled similar to __deprecated_attributes__, but raises an AttributeError with an informative message instead of a warning.

For example,

In [1]: import numpy as np                                                                           

In [2]: np.npv                                                                                       
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-ab016edb79d9> in <module>
----> 1 np.npv

~/mc38/lib/python3.8/site-packages/numpy-1.20.0.dev0+2558224-py3.8-macosx-10.9-x86_64.egg/numpy/__init__.py in __getattr__(attr)
    245             try:
    246                 msg = __expired_attrs__[attr]
--> 247                 raise AttributeError(msg)
    248             except KeyError:
    249                 pass

AttributeError: In accordance with NEP 32, the function npv 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

In Python 3.6, a plain AttributeError will be raised, but we will likely drop (official) support for 3.6 in the 1.20 release, so maybe that's OK.

This adds a bit more overhead when accessing the numpy namespace, so perhaps this isn't something we want to do.

@seberg
Copy link
Member

seberg commented Aug 12, 2020

@WarrenWeckesser thanks, it doesn't actually add additional overhead. The __getattr__ is only called if the item is not already found in the module dictionary. Or yes, it adds overhead, but only when attribute lookup fails :).

@WarrenWeckesser
Copy link
Member Author

@seberg, thanks, that's good to know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just put this into numpy/tests/test_public_api.py? Although, that file is mostly complex tests, so I don't care much.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but test_public_api.py seems to have a specific purpose in maintaing the "standard" numpy API. This new test doesn't seem to fit there. It didn't fit well anywhere, so I just put it into its own file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough :).

@seberg
Copy link
Member

seberg commented Aug 13, 2020

Thanks, Warren, pretty amazing to see this actually finished! Now I just wonder how much fallout we will see ;).

@seberg seberg merged commit b4fd7a7 into numpy:master Aug 13, 2020
@WarrenWeckesser WarrenWeckesser deleted the remove-financial branch August 14, 2020 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants