You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: numpy.convolve raises misleading ValueError on empty inputs due to internal variable swapping #30272
if (len(v) > len(a)):
a, v = v, a
if len(a) == 0:
raise ValueError('a cannot be empty')
if len(v) == 0:
raise ValueError('v cannot be empty')
Practically, this means if your first argument to convolve is empty, it will often incorrectly raise an error that says your second argument is empty.
Reproduce the code example:
importnumpyasnpa=np.array([]) # Emptyv=np.array([1, 2]) # Not empty# This triggers the swap, and internal state becomes: a=[1, 2], v=[]# Raises "v cannot be empty"np.convolve(a, v)
Error message:
ERROR!
Traceback (most recent call last):
File "<main.py>", line 8, in<module>
File "/usr/local/lib/python3.12/site-packages/numpy/_core/numeric.py", line 902, in convolve
raise ValueError('v cannot be empty')
ValueError: v cannot be empty
Python and NumPy Versions:
v2.3.0
Runtime Environment:
No response
Context for the issue:
Working in jax, I wasted a hour trying to figure out how my second argument could possibly be empty. Eventually I realized numpy was pointing me to the wrong argument and found my bug in the first array.
changed the title [-]BUG: numpy.convolve raises misleading ValueError on empty inputs due to internal variable swapping[/-][+]BUG: ``numpy.convolve`` raises misleading ``ValueError`` on empty inputs due to internal variable swapping[/+]on Nov 20, 2025
Activity
[-]BUG: numpy.convolve raises misleading ValueError on empty inputs due to internal variable swapping[/-][+]BUG: ``numpy.convolve`` raises misleading ``ValueError`` on empty inputs due to internal variable swapping[/+]Jongwan93 commentedon Nov 20, 2025
Hi I'd like to work on this issue
mattip commentedon Nov 21, 2025
We don't assign issues. When you push a PR to fix this be sure to link back to here with something like
Fixes #30272.