summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2015-08-29 18:46:21 -0600
committerCharles Harris <charlesr.harris@gmail.com>2015-09-06 16:36:42 -0600
commitc87c7a612ee7f90281797e447255c402b099c73a (patch)
tree4e761ce48aa0e79bead72b563217545ba2037c75 /numpy
parent7001d613aaa445ff650a273ec3d4db6787daf2e3 (diff)
downloadnumpy-c87c7a612ee7f90281797e447255c402b099c73a.tar.gz
DEP,MAINT: Change deprecated indexing to errors.
The deprecated operations changed to errors are * Conversion of floats and booleans to npy_intp indexes. * Conversion of single element integer arrays of ndim > 1 to indexes. * Multiple ellipsis in index. The affected deprecation tests have been been changed to check for raised errors instead, but remain in test_deprecations.py for the moment. They will be moved when the conversion of the remaining indexing deprecations is complete.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/conversion_utils.c94
-rw-r--r--numpy/core/src/multiarray/mapping.c126
-rw-r--r--numpy/core/src/multiarray/number.c13
-rw-r--r--numpy/core/tests/test_deprecations.py164
-rw-r--r--numpy/core/tests/test_indexing.py10
-rw-r--r--numpy/lib/tests/test_function_base.py18
6 files changed, 104 insertions, 321 deletions
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c
index 3b9a10da5..88064c1d6 100644
--- a/numpy/core/src/multiarray/conversion_utils.c
+++ b/numpy/core/src/multiarray/conversion_utils.c
@@ -777,20 +777,16 @@ PyArray_PyIntAsIntp_ErrMsg(PyObject *o, const char * msg)
#endif
PyObject *obj, *err;
- if (!o) {
+ /*
+ * Be a bit stricter and not allow bools.
+ * np.bool_ is also disallowed as Boolean arrays do not currently
+ * support index.
+ */
+ if (!o || PyBool_Check(o) || PyArray_IsScalar(o, Bool)) {
PyErr_SetString(PyExc_TypeError, msg);
return -1;
}
- /* Be a bit stricter and not allow bools, np.bool_ is handled later */
- if (PyBool_Check(o)) {
- /* 2013-04-13, 1.8 */
- if (DEPRECATE("using a boolean instead of an integer"
- " will result in an error in the future") < 0) {
- return -1;
- }
- }
-
/*
* Since it is the usual case, first check if o is an integer. This is
* an exact check, since otherwise __index__ is used.
@@ -816,84 +812,22 @@ PyArray_PyIntAsIntp_ErrMsg(PyObject *o, const char * msg)
return (npy_intp)long_value;
}
- /* Disallow numpy.bool_. Boolean arrays do not currently support index. */
- if (PyArray_IsScalar(o, Bool)) {
- /* 2013-06-09, 1.8 */
- if (DEPRECATE("using a boolean instead of an integer"
- " will result in an error in the future") < 0) {
- return -1;
- }
- }
-
/*
* The most general case. PyNumber_Index(o) covers everything
* including arrays. In principle it may be possible to replace
* the whole function by PyIndex_AsSSize_t after deprecation.
*/
obj = PyNumber_Index(o);
- if (obj) {
+ if (obj == NULL) {
+ return -1;
+ }
#if (NPY_SIZEOF_LONG < NPY_SIZEOF_INTP)
- long_value = PyLong_AsLongLong(obj);
+ long_value = PyLong_AsLongLong(obj);
#else
- long_value = PyLong_AsLong(obj);
+ long_value = PyLong_AsLong(obj);
#endif
- Py_DECREF(obj);
- goto finish;
- }
- else {
- /*
- * Set the TypeError like PyNumber_Index(o) would after trying
- * the general case.
- */
- PyErr_Clear();
- }
+ Py_DECREF(obj);
- /*
- * For backward compatibility check the number C-Api number protcol
- * This should be removed up the finish label after deprecation.
- */
- if (Py_TYPE(o)->tp_as_number != NULL &&
- Py_TYPE(o)->tp_as_number->nb_int != NULL) {
- obj = Py_TYPE(o)->tp_as_number->nb_int(o);
- if (obj == NULL) {
- return -1;
- }
- #if (NPY_SIZEOF_LONG < NPY_SIZEOF_INTP)
- long_value = PyLong_AsLongLong(obj);
- #else
- long_value = PyLong_AsLong(obj);
- #endif
- Py_DECREF(obj);
- }
-#if !defined(NPY_PY3K)
- else if (Py_TYPE(o)->tp_as_number != NULL &&
- Py_TYPE(o)->tp_as_number->nb_long != NULL) {
- obj = Py_TYPE(o)->tp_as_number->nb_long(o);
- if (obj == NULL) {
- return -1;
- }
- #if (NPY_SIZEOF_LONG < NPY_SIZEOF_INTP)
- long_value = PyLong_AsLongLong(obj);
- #else
- long_value = PyLong_AsLong(obj);
- #endif
- Py_DECREF(obj);
- }
-#endif
- else {
- PyErr_SetString(PyExc_TypeError, msg);
- return -1;
- }
- /* Give a deprecation warning, unless there was already an error */
- if (!error_converting(long_value)) {
- /* 2013-04-13, 1.8 */
- if (DEPRECATE("using a non-integer number instead of an integer"
- " will result in an error in the future") < 0) {
- return -1;
- }
- }
-
- finish:
if (error_converting(long_value)) {
err = PyErr_Occurred();
/* Only replace TypeError's here, which are the normal errors. */
@@ -902,9 +836,9 @@ PyArray_PyIntAsIntp_ErrMsg(PyObject *o, const char * msg)
}
return -1;
}
-
goto overflow_check; /* silence unused warning */
- overflow_check:
+
+overflow_check:
#if (NPY_SIZEOF_LONG < NPY_SIZEOF_INTP)
#if (NPY_SIZEOF_LONGLONG > NPY_SIZEOF_INTP)
if ((long_value < NPY_MIN_INTP) || (long_value > NPY_MAX_INTP)) {
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c
index b6e831498..42a12db14 100644
--- a/numpy/core/src/multiarray/mapping.c
+++ b/numpy/core/src/multiarray/mapping.c
@@ -285,35 +285,13 @@ prepare_index(PyArrayObject *self, PyObject *index,
/* Index is an ellipsis (`...`) */
if (obj == Py_Ellipsis) {
- /*
- * If there is more then one Ellipsis, it is replaced. Deprecated,
- * since it is hard to imagine anyone using two Ellipsis and
- * actually planning on all but the first being automatically
- * replaced with a slice.
- */
+ /* At most one ellipsis in an index */
if (index_type & HAS_ELLIPSIS) {
- /* 2013-04-14, 1.8 */
- if (DEPRECATE(
- "an index can only have a single Ellipsis (`...`); "
- "replace all but one with slices (`:`).") < 0) {
- goto failed_building_indices;
- }
- index_type |= HAS_SLICE;
-
- indices[curr_idx].type = HAS_SLICE;
- indices[curr_idx].object = PySlice_New(NULL, NULL, NULL);
-
- if (indices[curr_idx].object == NULL) {
- goto failed_building_indices;
- }
-
- used_ndim += 1;
- new_ndim += 1;
- curr_idx += 1;
- continue;
+ PyErr_Format(PyExc_IndexError,
+ "an index can only have a single ellipsis ('...')");
+ goto failed_building_indices;
}
index_type |= HAS_ELLIPSIS;
-
indices[curr_idx].type = HAS_ELLIPSIS;
indices[curr_idx].object = NULL;
/* number of slices it is worth, won't update if it is 0: */
@@ -415,102 +393,8 @@ prepare_index(PyArrayObject *self, PyObject *index,
goto failed_building_indices;
}
}
- /*
- * Special case to allow 0-d boolean indexing with
- * scalars. Should be removed after boolean-array
- * like as integer-array like deprecation.
- * (does not cover ufunc.at, because it does not use the
- * boolean special case, but that should not matter...)
- * Since all but strictly boolean indices are invalid,
- * there is no need for any further conversion tries.
- */
- else if (PyArray_NDIM(self) == 0) {
- arr = tmp_arr;
- }
else {
- /*
- * These Checks can be removed after deprecation, since
- * they should then be either correct already or error out
- * later just like a normal array.
- */
- if (PyArray_ISBOOL(tmp_arr)) {
- /* 2013-04-14, 1.8 */
- if (DEPRECATE_FUTUREWARNING(
- "in the future, boolean array-likes will be "
- "handled as a boolean array index") < 0) {
- Py_DECREF(tmp_arr);
- goto failed_building_indices;
- }
- if (PyArray_NDIM(tmp_arr) == 0) {
- /*
- * Need to raise an error here, since the
- * DeprecationWarning before was not triggered.
- * TODO: A `False` triggers a Deprecation *not* a
- * a FutureWarning.
- */
- PyErr_SetString(PyExc_IndexError,
- "in the future, 0-d boolean arrays will be "
- "interpreted as a valid boolean index");
- Py_DECREF(tmp_arr);
- goto failed_building_indices;
- }
- else {
- arr = tmp_arr;
- }
- }
- /*
- * Note: Down the road, the integers will be cast to intp.
- * The user has to make sure they can be safely cast.
- * If not, we might index wrong instead of an giving
- * an error.
- */
- else if (!PyArray_ISINTEGER(tmp_arr)) {
- if (PyArray_NDIM(tmp_arr) == 0) {
- /* match integer deprecation warning */
- /* 2013-09-25, 1.8 */
- if (DEPRECATE(
- "using a non-integer number instead of an "
- "integer will result in an error in the "
- "future") < 0) {
-
- /* The error message raised in the future */
- PyErr_SetString(PyExc_IndexError,
- "only integers, slices (`:`), ellipsis (`...`), "
- "numpy.newaxis (`None`) and integer or boolean "
- "arrays are valid indices");
- Py_DECREF((PyObject *)tmp_arr);
- goto failed_building_indices;
- }
- }
- else {
- /* 2013-09-25, 1.8 */
- if (DEPRECATE(
- "non integer (and non boolean) array-likes "
- "will not be accepted as indices in the "
- "future") < 0) {
-
- /* Error message to be raised in the future */
- PyErr_SetString(PyExc_IndexError,
- "non integer (and non boolean) array-likes will "
- "not be accepted as indices in the future");
- Py_DECREF((PyObject *)tmp_arr);
- goto failed_building_indices;
- }
- }
- }
-
- arr = (PyArrayObject *)PyArray_FromArray(tmp_arr,
- PyArray_DescrFromType(NPY_INTP),
- NPY_ARRAY_FORCECAST);
-
- if (arr == NULL) {
- /* Since this will be removed, handle this later */
- PyErr_Clear();
- arr = tmp_arr;
- }
- else {
- Py_DECREF((PyObject *)tmp_arr);
- }
+ arr = tmp_arr;
}
}
else {
diff --git a/numpy/core/src/multiarray/number.c b/numpy/core/src/multiarray/number.c
index 953a84eef..fec015a30 100644
--- a/numpy/core/src/multiarray/number.c
+++ b/numpy/core/src/multiarray/number.c
@@ -1025,18 +1025,11 @@ _array_copy_nice(PyArrayObject *self)
static PyObject *
array_index(PyArrayObject *v)
{
- if (!PyArray_ISINTEGER(v) || PyArray_SIZE(v) != 1) {
- PyErr_SetString(PyExc_TypeError, "only integer arrays with " \
- "one element can be converted to an index");
+ if (!PyArray_ISINTEGER(v) || PyArray_NDIM(v) != 0) {
+ PyErr_SetString(PyExc_TypeError,
+ "only integer scalar arrays can be converted to a scalar index");
return NULL;
}
- if (PyArray_NDIM(v) != 0) {
- /* 2013-04-20, 1.8 */
- if (DEPRECATE("converting an array with ndim > 0 to an index"
- " will result in an error in the future") < 0) {
- return NULL;
- }
- }
return PyArray_DESCR(v)->f->getitem(PyArray_DATA(v), v);
}
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index 8ec0f5e7f..c5f69fc00 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -144,34 +144,31 @@ class TestFloatNonIntegerArgumentDeprecation(_DeprecationTestCase):
def test_indexing(self):
a = np.array([[[5]]])
- def assert_deprecated(*args, **kwargs):
- self.assert_deprecated(*args, exceptions=(IndexError,), **kwargs)
-
- assert_deprecated(lambda: a[0.0])
- assert_deprecated(lambda: a[0, 0.0])
- assert_deprecated(lambda: a[0.0, 0])
- assert_deprecated(lambda: a[0.0,:])
- assert_deprecated(lambda: a[:, 0.0])
- assert_deprecated(lambda: a[:, 0.0,:])
- assert_deprecated(lambda: a[0.0,:,:])
- assert_deprecated(lambda: a[0, 0, 0.0])
- assert_deprecated(lambda: a[0.0, 0, 0])
- assert_deprecated(lambda: a[0, 0.0, 0])
- assert_deprecated(lambda: a[-1.4])
- assert_deprecated(lambda: a[0, -1.4])
- assert_deprecated(lambda: a[-1.4, 0])
- assert_deprecated(lambda: a[-1.4,:])
- assert_deprecated(lambda: a[:, -1.4])
- assert_deprecated(lambda: a[:, -1.4,:])
- assert_deprecated(lambda: a[-1.4,:,:])
- assert_deprecated(lambda: a[0, 0, -1.4])
- assert_deprecated(lambda: a[-1.4, 0, 0])
- assert_deprecated(lambda: a[0, -1.4, 0])
+ assert_raises(IndexError, lambda: a[0.0])
+ assert_raises(IndexError, lambda: a[0, 0.0])
+ assert_raises(IndexError, lambda: a[0.0, 0])
+ assert_raises(IndexError, lambda: a[0.0,:])
+ assert_raises(IndexError, lambda: a[:, 0.0])
+ assert_raises(IndexError, lambda: a[:, 0.0,:])
+ assert_raises(IndexError, lambda: a[0.0,:,:])
+ assert_raises(IndexError, lambda: a[0, 0, 0.0])
+ assert_raises(IndexError, lambda: a[0.0, 0, 0])
+ assert_raises(IndexError, lambda: a[0, 0.0, 0])
+ assert_raises(IndexError, lambda: a[-1.4])
+ assert_raises(IndexError, lambda: a[0, -1.4])
+ assert_raises(IndexError, lambda: a[-1.4, 0])
+ assert_raises(IndexError, lambda: a[-1.4,:])
+ assert_raises(IndexError, lambda: a[:, -1.4])
+ assert_raises(IndexError, lambda: a[:, -1.4,:])
+ assert_raises(IndexError, lambda: a[-1.4,:,:])
+ assert_raises(IndexError, lambda: a[0, 0, -1.4])
+ assert_raises(IndexError, lambda: a[-1.4, 0, 0])
+ assert_raises(IndexError, lambda: a[0, -1.4, 0])
# Test that the slice parameter deprecation warning doesn't mask
# the scalar index warning.
- assert_deprecated(lambda: a[0.0:, 0.0], num=2)
- assert_deprecated(lambda: a[0.0:, 0.0,:], num=2)
+ assert_raises(IndexError, lambda: a[0.0:, 0.0])
+ assert_raises(IndexError, lambda: a[0.0:, 0.0,:])
def test_valid_indexing(self):
a = np.array([[[5]]])
@@ -186,36 +183,33 @@ class TestFloatNonIntegerArgumentDeprecation(_DeprecationTestCase):
def test_slicing(self):
a = np.array([[5]])
- def assert_deprecated(*args, **kwargs):
- self.assert_deprecated(*args, exceptions=(IndexError,), **kwargs)
-
# start as float.
- assert_deprecated(lambda: a[0.0:])
- assert_deprecated(lambda: a[0:, 0.0:2])
- assert_deprecated(lambda: a[0.0::2, :0])
- assert_deprecated(lambda: a[0.0:1:2,:])
- assert_deprecated(lambda: a[:, 0.0:])
+ assert_raises(IndexError, lambda: a[0.0:])
+ assert_raises(IndexError, lambda: a[0:, 0.0:2])
+ assert_raises(IndexError, lambda: a[0.0::2, :0])
+ assert_raises(IndexError, lambda: a[0.0:1:2,:])
+ assert_raises(IndexError, lambda: a[:, 0.0:])
# stop as float.
- assert_deprecated(lambda: a[:0.0])
- assert_deprecated(lambda: a[:0, 1:2.0])
- assert_deprecated(lambda: a[:0.0:2, :0])
- assert_deprecated(lambda: a[:0.0,:])
- assert_deprecated(lambda: a[:, 0:4.0:2])
+ assert_raises(IndexError, lambda: a[:0.0])
+ assert_raises(IndexError, lambda: a[:0, 1:2.0])
+ assert_raises(IndexError, lambda: a[:0.0:2, :0])
+ assert_raises(IndexError, lambda: a[:0.0,:])
+ assert_raises(IndexError, lambda: a[:, 0:4.0:2])
# step as float.
- assert_deprecated(lambda: a[::1.0])
- assert_deprecated(lambda: a[0:, :2:2.0])
- assert_deprecated(lambda: a[1::4.0, :0])
- assert_deprecated(lambda: a[::5.0,:])
- assert_deprecated(lambda: a[:, 0:4:2.0])
+ assert_raises(IndexError, lambda: a[::1.0])
+ assert_raises(IndexError, lambda: a[0:, :2:2.0])
+ assert_raises(IndexError, lambda: a[1::4.0, :0])
+ assert_raises(IndexError, lambda: a[::5.0,:])
+ assert_raises(IndexError, lambda: a[:, 0:4:2.0])
# mixed.
- assert_deprecated(lambda: a[1.0:2:2.0], num=2)
- assert_deprecated(lambda: a[1.0::2.0], num=2)
- assert_deprecated(lambda: a[0:, :2.0:2.0], num=2)
- assert_deprecated(lambda: a[1.0:1:4.0, :0], num=2)
- assert_deprecated(lambda: a[1.0:5.0:5.0,:], num=3)
- assert_deprecated(lambda: a[:, 0.4:4.0:2.0], num=3)
+ assert_raises(IndexError, lambda: a[1.0:2:2.0])
+ assert_raises(IndexError, lambda: a[1.0::2.0])
+ assert_raises(IndexError, lambda: a[0:, :2.0:2.0])
+ assert_raises(IndexError, lambda: a[1.0:1:4.0, :0])
+ assert_raises(IndexError, lambda: a[1.0:5.0:5.0,:])
+ assert_raises(IndexError, lambda: a[:, 0.4:4.0:2.0])
# should still get the DeprecationWarning if step = 0.
- assert_deprecated(lambda: a[::0.0], function_fails=True)
+ assert_raises(IndexError, lambda: a[::0.0])
def test_valid_slicing(self):
a = np.array([[[5]]])
@@ -233,25 +227,25 @@ class TestFloatNonIntegerArgumentDeprecation(_DeprecationTestCase):
def test_non_integer_argument_deprecations(self):
a = np.array([[5]])
- self.assert_deprecated(np.reshape, args=(a, (1., 1., -1)), num=2)
- self.assert_deprecated(np.reshape, args=(a, (np.array(1.), -1)))
- self.assert_deprecated(np.take, args=(a, [0], 1.))
- self.assert_deprecated(np.take, args=(a, [0], np.float64(1.)))
+ assert_raises(TypeError, np.reshape, a, (1., 1., -1))
+ assert_raises(TypeError, np.reshape, a, (np.array(1.), -1))
+ assert_raises(TypeError, np.take, a, [0], 1.)
+ assert_raises(TypeError, np.take, a, [0], np.float64(1.))
def test_non_integer_sequence_multiplication(self):
# Numpy scalar sequence multiply should not work with non-integers
def mult(a, b):
return a * b
- self.assert_deprecated(mult, args=([1], np.float_(3)))
+ assert_raises(TypeError, mult, [1], np.float_(3))
self.assert_not_deprecated(mult, args=([1], np.int_(3)))
def test_reduce_axis_float_index(self):
d = np.zeros((3,3,3))
- self.assert_deprecated(np.min, args=(d, 0.5))
- self.assert_deprecated(np.min, num=1, args=(d, (0.5, 1)))
- self.assert_deprecated(np.min, num=1, args=(d, (1, 2.2)))
- self.assert_deprecated(np.min, num=2, args=(d, (.2, 1.2)))
+ assert_raises(TypeError, np.min, d, 0.5)
+ assert_raises(TypeError, np.min, d, (0.5, 1))
+ assert_raises(TypeError, np.min, d, (1, 2.2))
+ assert_raises(TypeError, np.min, d, (.2, 1.2))
class TestBooleanArgumentDeprecation(_DeprecationTestCase):
@@ -267,15 +261,15 @@ class TestBooleanArgumentDeprecation(_DeprecationTestCase):
def test_bool_as_int_argument(self):
a = np.array([[[1]]])
- self.assert_deprecated(np.reshape, args=(a, (True, -1)))
- self.assert_deprecated(np.reshape, args=(a, (np.bool_(True), -1)))
+ assert_raises(TypeError, np.reshape, a, (True, -1))
+ assert_raises(TypeError, np.reshape, a, (np.bool_(True), -1))
# Note that operator.index(np.array(True)) does not work, a boolean
# array is thus also deprecated, but not with the same message:
assert_raises(TypeError, operator.index, np.array(True))
- self.assert_deprecated(np.take, args=(a, [0], False))
- self.assert_deprecated(lambda: a[False:True:True], exceptions=IndexError, num=3)
- self.assert_deprecated(lambda: a[False, 0], exceptions=IndexError)
- self.assert_deprecated(lambda: a[False, 0, 0], exceptions=IndexError)
+ assert_raises(TypeError, np.take, args=(a, [0], False))
+ assert_raises(IndexError, lambda: a[False:True:True])
+ assert_raises(IndexError, lambda: a[False, 0])
+ assert_raises(IndexError, lambda: a[False, 0, 0])
class TestArrayToIndexDeprecation(_DeprecationTestCase):
@@ -294,11 +288,13 @@ class TestArrayToIndexDeprecation(_DeprecationTestCase):
# so no exception is expected. The raising is effectively tested above.
a = np.array([[[1]]])
- self.assert_deprecated(operator.index, args=(np.array([1]),))
- self.assert_deprecated(np.reshape, args=(a, (a, -1)), exceptions=())
- self.assert_deprecated(np.take, args=(a, [0], a), exceptions=())
+ assert_raises(TypeError, operator.index, np.array([1]))
+ assert_raises(TypeError, np.reshape, a, (a, -1))
+ assert_raises(TypeError, np.take, a, [0], a)
+
# Check slicing. Normal indexing checks arrays specifically.
- self.assert_deprecated(lambda: a[a:a:a], exceptions=(), num=3)
+ assert_raises(IndexError, lambda: a[a:a:a])
+
class TestNonIntegerArrayLike(_DeprecationTestCase):
"""Tests that array likes, i.e. lists give a deprecation warning
@@ -309,26 +305,11 @@ class TestNonIntegerArrayLike(_DeprecationTestCase):
def test_basic(self):
a = np.arange(10)
- self.assert_deprecated(a.__getitem__, args=([0.5, 1.5],),
- exceptions=IndexError)
- self.assert_deprecated(a.__getitem__, args=((['1', '2'],),),
- exceptions=IndexError)
+ assert_raises(IndexError, a.__getitem__, [0.5, 1.5])
+ assert_raises(IndexError, a.__getitem__, (['1', '2'],))
self.assert_not_deprecated(a.__getitem__, ([],))
- def test_boolean_futurewarning(self):
- a = np.arange(10)
- with warnings.catch_warnings():
- warnings.filterwarnings('always')
- assert_warns(FutureWarning, a.__getitem__, [True])
- # Unfortunatly, the deprecation warning takes precedence:
- #assert_warns(FutureWarning, a.__getitem__, True)
-
- with warnings.catch_warnings():
- warnings.filterwarnings('error')
- assert_raises(FutureWarning, a.__getitem__, [True])
- #assert_raises(FutureWarning, a.__getitem__, True)
-
class TestMultipleEllipsisDeprecation(_DeprecationTestCase):
message = "an index can only have a single Ellipsis \(`...`\); replace " \
@@ -336,14 +317,9 @@ class TestMultipleEllipsisDeprecation(_DeprecationTestCase):
def test_basic(self):
a = np.arange(10)
- self.assert_deprecated(a.__getitem__, args=((Ellipsis, Ellipsis),))
-
- with warnings.catch_warnings():
- warnings.filterwarnings('ignore', '', DeprecationWarning)
- # Just check that this works:
- b = a[...,...]
- assert_array_equal(a, b)
- assert_raises(IndexError, a.__getitem__, ((Ellipsis, ) * 3,))
+ assert_raises(IndexError, lambda : a[..., ...])
+ assert_raises(IndexError, a.__getitem__, ((Ellipsis,) * 2,))
+ assert_raises(IndexError, a.__getitem__, ((Ellipsis,) * 3,))
class TestBooleanUnaryMinusDeprecation(_DeprecationTestCase):
diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py
index 4bc937e0b..ef876a622 100644
--- a/numpy/core/tests/test_indexing.py
+++ b/numpy/core/tests/test_indexing.py
@@ -35,16 +35,6 @@ class TestIndexing(TestCase):
a = np.array(0)
assert_(isinstance(a[()], np.int_))
- # Regression, it needs to fall through integer and fancy indexing
- # cases, so need the with statement to ignore the non-integer error.
- with warnings.catch_warnings():
- warnings.filterwarnings('ignore', '', DeprecationWarning)
- a = np.array([1.])
- assert_(isinstance(a[0.], np.float_))
-
- a = np.array([np.array(1)], dtype=object)
- assert_(isinstance(a[0.], np.ndarray))
-
def test_same_kind_index_casting(self):
# Indexes should be cast with same-kind and not safe, even if
# that is somewhat unsafe. So test various different code paths.
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index af9315d83..8a814e168 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -1888,19 +1888,25 @@ class TestBincount(TestCase):
def test_with_incorrect_minlength(self):
x = np.array([], dtype=int)
- assert_raises_regex(TypeError, "an integer is required",
+ assert_raises_regex(TypeError,
+ "'str' object cannot be interpreted",
lambda: np.bincount(x, minlength="foobar"))
- assert_raises_regex(ValueError, "must be positive",
+ assert_raises_regex(ValueError,
+ "must be positive",
lambda: np.bincount(x, minlength=-1))
- assert_raises_regex(ValueError, "must be positive",
+ assert_raises_regex(ValueError,
+ "must be positive",
lambda: np.bincount(x, minlength=0))
x = np.arange(5)
- assert_raises_regex(TypeError, "an integer is required",
+ assert_raises_regex(TypeError,
+ "'str' object cannot be interpreted",
lambda: np.bincount(x, minlength="foobar"))
- assert_raises_regex(ValueError, "minlength must be positive",
+ assert_raises_regex(ValueError,
+ "minlength must be positive",
lambda: np.bincount(x, minlength=-1))
- assert_raises_regex(ValueError, "minlength must be positive",
+ assert_raises_regex(ValueError,
+ "minlength must be positive",
lambda: np.bincount(x, minlength=0))