diff options
-rw-r--r-- | numpy/core/src/multiarray/item_selection.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 12 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 9 |
3 files changed, 22 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c index 4bc546ee7..d3b9a036d 100644 --- a/numpy/core/src/multiarray/item_selection.c +++ b/numpy/core/src/multiarray/item_selection.c @@ -1722,7 +1722,7 @@ PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2, } /* ret is a contiguous array of intp type to hold returned indexes */ - ret = (PyArrayObject *)PyArray_New(Py_TYPE(ap2), PyArray_NDIM(ap2), + ret = (PyArrayObject *)PyArray_New(&PyArray_Type, PyArray_NDIM(ap2), PyArray_DIMS(ap2), NPY_INTP, NULL, NULL, 0, 0, (PyObject *)ap2); if (ret == NULL) { diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 8ec910a42..633dfd194 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -1526,6 +1526,18 @@ class TestMethods(TestCase): b = a.searchsorted(a, 'r', s) assert_equal(b, out + 1) + def test_searchsorted_return_type(self): + # Functions returning indices should always return base ndarrays + class A(np.ndarray): + pass + a = np.arange(5).view(A) + b = np.arange(1, 3).view(A) + s = np.arange(5).view(A) + assert_(not isinstance(a.searchsorted(b, 'l'), A)) + assert_(not isinstance(a.searchsorted(b, 'r'), A)) + assert_(not isinstance(a.searchsorted(b, 'l', s), A)) + assert_(not isinstance(a.searchsorted(b, 'r', s), A)) + def test_argpartition_out_of_range(self): # Test out of range values in kth raise an error, gh-5469 d = np.arange(10) diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index b29012bcb..c8e2c2128 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -913,6 +913,15 @@ class TestDigitize(TestCase): x, bins = bins, x assert_raises(TypeError, digitize, x, bins) + def test_return_type(self): + # Functions returning indices should always return base ndarrays + class A(np.ndarray): + pass + a = np.arange(5).view(A) + b = np.arange(1, 3).view(A) + assert_(not isinstance(digitize(b, a, False), A)) + assert_(not isinstance(digitize(b, a, True), A)) + class TestUnwrap(TestCase): |