Skip to content

Commit

Permalink
Merge pull request #24484 from ngoldbaum/choose-fix
Browse files Browse the repository at this point in the history
BUG: fix NPY_cast_info error handling in choose
  • Loading branch information
charris committed Aug 22, 2023
2 parents 97d1d31 + 9cfb416 commit 0450bc4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/item_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *out,
PyArrayObject **mps, *ap;
PyArrayMultiIterObject *multi = NULL;
npy_intp mi;
NPY_cast_info cast_info = {.func = NULL};
ap = NULL;

/*
Expand Down Expand Up @@ -1045,7 +1046,6 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *out,
npy_intp transfer_strides[2] = {elsize, elsize};
npy_intp one = 1;
NPY_ARRAYMETHOD_FLAGS transfer_flags = 0;
NPY_cast_info cast_info = {.func = NULL};
if (PyDataType_REFCHK(dtype)) {
int is_aligned = IsUintAligned(obj);
PyArray_GetDTypeTransferFunction(
Expand Down
6 changes: 6 additions & 0 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -10043,3 +10043,9 @@ def test_gh_22683():
np.choose(np.zeros(10000, dtype=int), [a], out=a)
refc_end = sys.getrefcount(b)
assert refc_end - refc_start < 10


def test_gh_24459():
a = np.zeros((50, 3), dtype=np.float64)
with pytest.raises(TypeError):
np.choose(a, [3, -1])

0 comments on commit 0450bc4

Please sign in to comment.