8000 MAINT: more informative error message from linalg.norm by ewmoore · Pull Request #5210 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: more informative error message from linalg.norm #5210

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 1 commit into from
Oct 20, 2014

Conversation

ewmoore
Copy link
Contributor
@ewmoore ewmoore commented Oct 20, 2014

From the discussion in #5196, provides a better error message for a bad axis specification in np.linalg.norm. The other cases should be handled eventually by which ever ufunc ends up being called. This particular case needs handled because norm wraps anything that isn't a tuple in a tuple. If that happened to be a list, you would receive an error asking for an int. So. np.linalg.norm(a, axis=[0,1]) failed with an unhelpful error even accounting for #5201.

try:
axis = int(axis)
except:
raise TypeError("`axis` must be None, an integer or a tuple of integers")
Copy link
Member

Choose a reason for hiding this comment

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

Markdown burns quickly into muscle memory, but in error messages we typically use single quotes ', not backticks```, when emphasizing an argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected.

This specifically addresses passing things like axis=[0,1] which
gave an error message that an int was required.  The real error
was that if the axis isn't None or a tuple, it was simply wraped
in a tuple, so the ufunc that is eventually called ended up with
a list.  The error message is matches that in
core/src/multiarray/conversion_utils.c::PyArray_ConvertMultiAxis.
jaimefrio added a commit that referenced this pull request Oct 20, 2014
MAINT: more informative error message from linalg.norm
@jaimefrio jaimefrio merged commit 4ed4aec into numpy:master Oct 20, 2014
@jaimefrio
Copy link
Member

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0