
On Fri, Nov 11, 2022 at 2:47 PM Sebastian Berg <sebastian@sipsolutions.net> wrote:
Hi all,
I want to add a new exception or two. It is a longer story, that you can find at the bottom :).
Lets create a namespace for custom errors! I don't want to propose new exceptions that just get dumped in to the main namespace, so why not make one like `errors` in pandas or `exceptions` in scikit-learn.
I would suggest introducing `np.exceptions`.
We already have custom errors and warnings:
* AxisError * TooHardError (used by `np.shares_memory()`) * ComplexWarning * RankWarning * VisibleDeprecationWarning * ModuleDeprecationWarning (not sure what this is)
And a few private ones around ufunc "no loops" or casting failures (for delayed printing and formatting convenience).
No need to move them all now, but maybe it is time to create a module where we put them all? With the intention that when the stars align, we will deprecate their main namespace aliases (either soon or in years).
Beyond the error I just wanted, there were things brought up before, such as either `BroadcastError` or `ShapeMismatch`. Adding the namespace would make them more discoverable and just remove an annoying road-block for adding new ones. I will argue that the cost is practically zero. I do not want custom exceptions for too many things, but there are probably good reasons to have more than we do have right now, and even the ones we have seem enough for a namespace.
This all sounds like a good idea to me, +1 Cheers, Ralf