Skip to content

Commit

Permalink
Auto merge of numpy#6206 - jaimefrio:searchsorted_ndarray, r=njsmith
Browse files Browse the repository at this point in the history
MANT: searchsorted should return base ndarrays always
  • Loading branch information
homu committed Aug 17, 2015
2 parents 6e8b869 + 649ede4 commit 4186b6d
Show file tree
Hide file tree
Showing 3 changed files with 22 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 @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,18 @@ def test_searchsorted_with_sorter(self):
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)
Expand Down
9 changes: 9 additions & 0 deletions numpy/lib/tests/test_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,15 @@ def test_casting_error(self):
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):

Expand Down

0 comments on commit 4186b6d

Please sign in to comment.