Skip to content

Fix incorrect grammar in TypeError message for ufunc argument count mismatch #29308

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 2 commits into from
Jul 2, 2025

Conversation

shyok21
Copy link
Contributor

@shyok21 shyok21 commented Jul 2, 2025

Summary

This PR fixes a grammatical issue in the TypeError message raised when a ufunc (such as np.hypot) receives an incorrect number of positional arguments.

Previously, the message always used:

hypot() takes from 2 to 3 positional arguments but 1 were given

This PR ensures that when exactly one argument is passed, the message reads:

hypot() takes from 2 to 3 positional arguments but 1 was given


Changes

  • Updated error message formatting logic in:
    • npy_argparse.c
    • ufunc_object.c
  • Added regression tests under test_umath.py to assert correct grammar for singular and plural argument count cases.

Related Issue

Closes #29259

Additional Notes

  • Follows TDD approach: test first, then fix.
  • Verified via pytest numpy/_core/tests/test_umath.py -k TestHypotErrorMessages
  • Thanks to maintainers for pointing to the relevant code sections.

@mattip mattip merged commit b999c61 into numpy:main Jul 2, 2025
77 checks passed
@mattip
Copy link
Member

mattip commented Jul 2, 2025

Thanks @shyok21

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.

Bad grammar in error message from hypot
2 participants