diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2017-06-27 07:33:41 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-27 07:33:41 -0600 |
commit | e9e3a3b387fd870b72e92e09ca5341e6bf306d4d (patch) | |
tree | 2aebe7f91ea750a97fb6f112efd5e8f5590eb323 | |
parent | f5eb5af5d47d4c59159a424169619d45d2140b67 (diff) | |
parent | 1b209d0c7d7d9e054f0b06a44595af1455db0c6a (diff) | |
download | numpy-e9e3a3b387fd870b72e92e09ca5341e6bf306d4d.tar.gz |
Merge pull request #9310 from juliantaylor/nonzero-fix
BUG: fix wrong ndim used in empty where check
-rw-r--r-- | numpy/core/src/multiarray/item_selection.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c index c88cdfdcb..e60145508 100644 --- a/numpy/core/src/multiarray/item_selection.c +++ b/numpy/core/src/multiarray/item_selection.c @@ -2330,7 +2330,7 @@ finish: return NULL; } - for (i = 0; i < ndim; ++i) { + for (i = 0; i < PyArray_NDIM(ret); ++i) { if (PyArray_DIMS(ret)[i] == 0) { is_empty = 1; break; diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 5060abc7b..3dde4ae2f 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -6656,6 +6656,17 @@ class TestWhere(TestCase): assert_array_equal(ibad, np.atleast_2d(np.array([[],[]], dtype=np.intp))) + def test_largedim(self): + # invalid read regression gh-9304 + shape = [10, 2, 3, 4, 5, 6] + np.random.seed(2) + array = np.random.rand(*shape) + + for i in range(10): + benchmark = array.nonzero() + result = array.nonzero() + assert_array_equal(benchmark, result) + if not IS_PYPY: # sys.getsizeof() is not valid on PyPy |