Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions numpy/_core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,17 @@ PyArray_ConcatenateInto(PyObject *op,
}

/* Convert the input list into arrays */
narrays = PySequence_Size(op);
if (narrays < 0) {
Py_ssize_t narrays_true = PySequence_Size(op);
if (narrays_true < 0) {
return NULL;
}
else if (narrays_true > NPY_MAX_INT) {
PyErr_Format(PyExc_ValueError,
"concatenate() only supports up to %d arrays but got %zd.",
NPY_MAX_INT, narrays_true);
return NULL;
}
narrays = (int)narrays_true;
arrays = PyArray_malloc(narrays * sizeof(arrays[0]));
if (arrays == NULL) {
PyErr_NoMemory();
Expand Down
14 changes: 14 additions & 0 deletions numpy/_core/tests/test_shape_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

import pytest

import numpy as np
Expand Down Expand Up @@ -29,6 +31,7 @@
assert_raises,
assert_raises_regex,
)
from numpy.testing._private.utils import requires_memory


class TestAtleast1d:
Expand Down Expand Up @@ -290,6 +293,17 @@ def test_exceptions(self):
# No arrays to concatenate raises ValueError
assert_raises(ValueError, concatenate, ())

@pytest.mark.slow
@pytest.mark.skipif(sys.maxsize < 2**32, reason="only problematic on 64bit platforms")
@requires_memory(2 * np.iinfo(np.intc).max)
def test_huge_list_error(self):
a = np.array([1])
max_int = np.iinfo(np.intc).max
arrs = (a,) * (max_int + 1)
msg = fr"concatenate\(\) only supports up to {max_int} arrays but got {max_int + 1}."
with pytest.raises(ValueError, match=msg):
np.concatenate(arrs)

def test_concatenate_axis_None(self):
a = np.arange(4, dtype=np.float64).reshape((2, 2))
b = list(range(3))
Expand Down
Loading