BUG: SystemError when calling numpy.resize with unsigned integer size
Describe the issue:
Calling np.resize() with an unsigned integer (e.g., np.uint32) as the second argument causes a RuntimeWarning about overflow in scalar negative, followed by a SystemError.
This issue occurs in NumPy versions 2.x (tested on v2.3.0 and v2.2.5), but may affect other versions.
Reproduce the code example:
import numpy as np
res = np.resize(np.array([[23, 95], [66, 37]]), np.int32(1))
print(res) # res = [23]
res = np.resize(np.array([[23, 95], [66, 37]]), np.uint32(1))
print(res) # SystemError: <built-in function concatenate> returned NULL without setting an exception
res = np.resize(np.array([[23, 95], [66, 37]]), np.uint64(1))
print(res) # OverflowError: cannot fit 'numpy.uint64' into an index-sized integer
Error message:
/data/install/Miniconda/envs/pbt/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:1611: RuntimeWarning: overflow encountered in scalar negative
repeats = -(-new_size // a.size) # ceil division
Traceback (most recent call last):
File "/data/PBT/script/test.py", line 30, in <module>
res = np.resize(np.array([[23, 95], [66, 37]]), np.uint32(1))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/install/Miniconda/envs/pbt/lib/python3.12/site-packages/numpy/_core/fromnumeric.py", line 1612, in resize
a = concatenate((a,) * repeats)[:new_size]
^^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <built-in function concatenate> returned NULL without setting an exception
Python and NumPy Versions:
2.2.5 3.12.0 | packaged by Anaconda, Inc. | (main, Oct 2 2023, 17:29:18) [GCC 11.2.0] or 2.3.0 3.13.5 | packaged by Anaconda, Inc. | (main, Jun 12 2025, 16:09:02) [GCC 11.2.0]
Runtime Environment:
[{'numpy_version': '2.3.0', 'python': '3.13.5 | packaged by Anaconda, Inc. | (main, Jun 12 2025, ' '16:09:02) [GCC 11.2.0]', 'uname': uname_result(system='Linux', node='node1', release='5.4.0-167-generic', version='#184-Ubuntu SMP Tue Oct 31 09:21:49 UTC 2023', machine='x86_64')}, {'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'], 'found': ['SSSE3', 'SSE41', 'POPCNT', 'SSE42', 'AVX', 'F16C', 'FMA3', 'AVX2', 'AVX512F', 'AVX512CD', 'AVX512_SKX', 'AVX512_CLX', 'AVX512_CNL', 'AVX512_ICL'], 'not_found': ['AVX512_KNL', 'AVX512_KNM', 'AVX512_SPR']}}, {'architecture': 'SkylakeX', 'filepath': '/data/install/Miniconda/envs/newest_version/lib/python3.13/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so', 'internal_api': 'openblas', 'num_threads': 64, 'prefix': 'libscipy_openblas', 'threading_layer': 'pthreads', 'user_api': 'blas', 'version': '0.3.29'}]
Context for the issue:
This issue affects workflows that involve dynamic array resizing based on external input values, especially when those values are provided as unsigned integers. In our case, this bug causes unexpected crashes in data preprocessing pipelines where shape parameters are passed as NumPy unsigned types. The crash is particularly problematic because:
- It does not raise a clear
TypeErrororValueError, making debugging difficult.
This is almost certainly some broken error checking in C code somewhere.
While there's certainly some screwed up error handling happening somewhere, I can't reproduce the SystemError on my development setup and https://github.com/numpy/numpy/pull/29230 seems to avoid the issue.
Got it, thanks for the clarification and the fix!
the fix isn't merged yet so reopening