From 0e8edab421e3b20ff2f4085e06040101c2d9865f Mon Sep 17 00:00:00 2001 From: jaimefrio Date: Sun, 7 Dec 2014 19:32:36 -0800 Subject: BUG: digitize segfaults on TypeError The new searchsorted-based digitize introduced in #5101 segfaults when it should raise a TypeError. --- numpy/lib/src/_compiled_base.c | 4 ++-- numpy/lib/tests/test_function_base.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'numpy/lib') diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c index 99aec38f0..9d9344526 100644 --- a/numpy/lib/src/_compiled_base.c +++ b/numpy/lib/src/_compiled_base.c @@ -295,8 +295,8 @@ arr_digitize(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds) } fail: - Py_DECREF(arr_x); - Py_DECREF(arr_bins); + Py_XDECREF(arr_x); + Py_XDECREF(arr_bins); return ret; } diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 80faf85a6..03521ca4c 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -861,6 +861,13 @@ class TestDigitize(TestCase): bins = [1, 1, 0, 1] assert_raises(ValueError, digitize, x, bins) + def test_casting_error(self): + x = [1, 2, 3+1.j] + bins = [1, 2, 3] + assert_raises(TypeError, digitize, x, bins) + x, bins = bins, x + assert_raises(TypeError, digitize, x, bins) + class TestUnwrap(TestCase): def test_simple(self): -- cgit v1.2.1