8000 API: Add new `np.exceptions` namespace for errors and warnings by seberg · Pull Request #22644 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

API: Add new np.exceptions namespace for errors and warnings #22644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 30, 2022

Conversation

seberg
Copy link
Member
@seberg seberg commented Nov 22, 2022

This adds the namespace and populates it with the main public exceptions and warnings that we have. I skipped RankWarning for now, because we have two (and only one is in the main namespace).
The UFuncTypeError is currently effectively private, so did not move it quite yet (this can be a followup).

Based of gh-22619 and thus creating as draft. I put 1.24 as version here, but most likely this will need updating.

The main point of this is really to simplify adding of new exceptions in the future, but I think the module doesn't really hurt even for 3 errors.

Mailing list thread where we discussed adding this module: https://mail.python.org/archives/list/numpy-discussion@python.org/thread/IZJQTPQBKNQGK4OGWSTREQWKGMQDSFKM/

.. warning::

This warning should not be used, since nose testing is not relvant
anymore.
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this warning, and skipped documenting it... It seems like a remnant of a time past.

@seberg
Copy link
Member Author
seberg commented Nov 24, 2022

Can we please move this (and the other PR there) forward? I (+do not see) potential for controversy or code complexity here, but:

  1. I need this to introduce new errors
  2. I need new errors to have a chance of fixing up the gigantic mess that has been around unfixed for years, that our == FutureWarning is. (The FutureWarning is good, but its useless if we don't know how to finalize it)
  3. I need THAT one to be able to paint a full picture of the option to make API: No timedelta/datetimes are not integers and do not promote #22568 happen.
  4. And that again, would at least help a little with clearing up the whole mess that find_common_type is.

I bet there is more, but my monkey brain can only hold 3 things at once.

AxisError Given when an axis was invalid.
TooHardError Error specific to `numpy.shares_memory`.

"""
Copy link
Member

Choose a reason for hiding this comment

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

Do we have autosummary elsewhere in a module docstring? This feels out of place to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm, fft and polynomials used it. But I am not sure the autosummary here is actually useful.

Copy link
Member

Choose a reason for hiding this comment

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

I still think this belongs somewhere else.

Copy link
Member Author

Choose a reason for hiding this comment

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

Where? Maybe @rossbar can just say.

Lines containing no data, including comment lines (e.g., lines
starting with '#' or as specified via `comments`) are not counted
Lines containing no data, including comment lines (e.g., lines
starting with '#' or as specified via `comments`) are not counted
towards `max_rows`.
quotechar : unicode character or None, optional
The character used to denote the start and end of a quoted item.
Copy link
Member

Choose a reason for hiding this comment

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

While I agree with the whitespace cleanup in files you are changing anyway, I don't think this one should be part of this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, not even an actual change left in the end here... (set_module is imported via overrides here, which seemed OKish.)

@charris
Copy link
Member
charris commented Nov 24, 2022

Note that this is still a WIP, might want to change that so it can be merged.

@mattip
Copy link
Member
mattip commented Nov 24, 2022

This is still draft status. For other reviewers: it has 3 components:

  • moving two warnings, another unused warning, and two exceptions into an exception namespace
  • adding a new _util namespace and moving set_module to there
  • cleaning up whitespace

@seberg
Copy link
Member Author
seberg commented Nov 24, 2022

I have a separate PR for moving the _set_module in gh-22619, the reason for the draft status.

Yeah can pull out the whitespace changes there, they were not really intended, just auto-stripping by the editor.

@seberg seberg force-pushed the exceptions branch 2 times, most recently from b7dfc6e to a82a155 Compare November 24, 2022 16:04
@mattip
Copy link
Member
mattip commented Nov 29, 2022

Is this ready to go? I quite like it.

@seberg seberg marked this pull request as ready for review November 30, 2022 07:52
@seberg
Copy link
Member Author
seberg commented Nov 30, 2022

Should be ready to go now, was missing a rebase on main still.

Comment on lines 65 to 66


Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

@@ -707,7 +694,7 @@ def correlate(a, v, mode='valid'):
--------
convolve : Discrete, linear convolution of two one-dimensional sequences.
multiarray.correlate : Old, no conjugate, version of correlate.
scipy.signal.correlate : uses FFT which has superior performance on large arrays.
scipy.signal.correlate : uses FFT which has superior performance on large arrays.
Copy link
Member

Choose a reason for hiding this comment

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

This is tripping up the linter since the line is 85, not 80. But I think it is OK.

Co-authored-by: Matti Picus <matti.picus@gmail.com>
@mattip mattip merged commit 9896b46 into numpy:main Nov 30, 2022
@mattip
Copy link
Member
mattip commented Nov 30, 2022

Thanks @seberg. There is still the documentation issue, but lets leave that for a future PR.

@seberg seberg deleted the exceptions branch November 30, 2022 21:58
BvB93 added a commit to BvB93/numpy that referenced this pull request May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0