Skip to content
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

MAINT: Better error message for linalg.norm #17882

Closed
wants to merge 1 commit into from

Conversation

ZhihuiChen0903
Copy link

For example:
numpy.linalg.norm(2, np.inf)

raises:
ValueError: Improper number of dimensions to norm.

The error messageis a bit vague.
This pull request changes the error message so that it explicitly states the expected dimensions.

Expected error message:
Input must be 1-D or 2-D when axis=None (unless ord is None)

@mattip
Copy link
Member

mattip commented Dec 2, 2020

It seems your error message would be displayed when calling np.norm(a, axis=(1, 2 3)), which would be confusing.

@ZhihuiChen0903
Copy link
Author

@mattip
Is it possible to provide more specific error in the error message?

@mattip
Copy link
Member

mattip commented Dec 4, 2020

You could do a specific check for len(axis) your error condition in an else clause on line 2534. Please add a test or point to an existing test that trips the new code.

@charris charris changed the title Better error message for linalg.norm MAINT: Better error message for linalg.norm Dec 27, 2020
Base automatically changed from master to main March 4, 2021 02:05
@InessaPawson
Copy link
Member

@ZhihuiChen0903 Thank you for sharing your solution! Do you think you could submit a requested test (#17882 (comment)) some time soon?

@InessaPawson InessaPawson added the 52 - Inactive Pending author response label Jan 26, 2023
@charris charris added 55 - Needs work 64 - Good Idea Inactive PR with a good start or idea. Consider studying it if you are working on a related issue. labels Feb 20, 2023
@charris
Copy link
Member

charris commented Feb 20, 2023

I'm going to close this. The error message could be improved, but is seems it needs more work to get it right. @ZhihuiChen0903 feel free to make another PR along these lines.

@charris charris closed this Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
03 - Maintenance 52 - Inactive Pending author response 55 - Needs work 59 - Needs tests 64 - Good Idea Inactive PR with a good start or idea. Consider studying it if you are working on a related issue. component: numpy.linalg
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants