8000 Merge pull request #7529 from simongibbons/lexsort_fix · numpy/numpy@0b2e590 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b2e590

Browse files
committed
Merge pull request #7529 from simongibbons/lexsort_fix
BUG: Floating exception with invalid axis in np.lexsort
2 parents 71575f1 + c2ec818 commit 0b2e590

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

numpy/core/src/multiarray/item_selection.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,11 +1441,6 @@ PyArray_LexSort(PyObject *sort_keys, int axis)
14411441
&& PyDataType_FLAGCHK(PyArray_DESCR(mps[i]), NPY_NEEDS_PYAPI)) {
14421442
object = 1;
14431443
}
1444-
its[i] = (PyArrayIterObject *)PyArray_IterAllButAxis(
1445-
(PyObject *)mps[i], &axis);
1446-
if (its[i] == NULL) {
1447-
goto fail;
1448-
}
14491444
}
14501445

14511446
/* Now we can check the axis */
@@ -1472,6 +1467,14 @@ PyArray_LexSort(PyObject *sort_keys, int axis)
14721467
goto fail;
14731468
}
14741469

1470+
for (i = 0; i < n; i++) {
1471+
its[i] = (PyArrayIterObject *)PyArray_IterAllButAxis(
1472+
(PyObject *)mps[i], &axis);
1473+
if (its[i] == NULL) {
1474+
goto fail;
1475+
}
1476+
}
1477+
14751478
/* Now do the sorting */
14761479
ret = (PyArrayObject *)PyArray_New(&PyArray_Type, PyArray_NDIM(mps[0]),
14771480
PyArray_DIMS(mps[0]), NPY_INTP,

numpy/core/tests/test_multiarray.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3614,6 +3614,9 @@ def test_object(self): # gh-6312
36143614
u, v = np.array(u, dtype='object'), np.array(v, dtype='object')
36153615
assert_array_equal(idx, np.lexsort((u, v)))
36163616

3617+
def test_invalid_axis(self): # gh-7528
3618+
x = np.linspace(0., 1., 42*3).reshape(42, 3)
3619+
assert_raises(ValueError, np.lexsort, x, axis=2)
36173620

36183621
class TestIO(object):
36193622
"""Test tofile, fromfile, tobytes, and fromstring"""

0 commit comments

Comments
 (0)
0