summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-09-17 17:38:24 -0700
committerEric Wieser <wieser.eric@gmail.com>2017-09-17 17:38:24 -0700
commit04b14d633c41f909a81e349df391e6843179e264 (patch)
tree07618a01a6ee788caee8667c7ea69af80d8b2766 /numpy
parent448ac032542db9dd7c3cccbbd65a36e9227a3ec2 (diff)
downloadnumpy-04b14d633c41f909a81e349df391e6843179e264.tar.gz
DEP: Warn when using bool.__index__, rather than removing it completely
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src11
-rw-r--r--numpy/core/tests/test_indexing.py2
2 files changed, 9 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index 1c809f409..7ccdd579a 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -2843,9 +2843,14 @@ static PyNumberMethods @name@_arrtype_as_number;
static PyObject *
bool_index(PyObject *a)
{
- PyErr_SetString(PyExc_TypeError,
- "A boolean scalar cannot be converted to an index");
- return NULL;
+ if (DEPRECATE(
+ "In future, it will be an error for 'np.bool_' scalars to be "
+ "interpreted as an index") < 0) {
+ return NULL;
+ }
+ else {
+ return PyInt_FromLong(PyArrayScalar_VAL(a, Bool));
+ }
}
/* Arithmetic methods -- only so we can override &, |, ^. */
diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py
index 9259bb9d4..7cfb81da7 100644
--- a/numpy/core/tests/test_indexing.py
+++ b/numpy/core/tests/test_indexing.py
@@ -1174,7 +1174,7 @@ class TestBooleanIndexing(object):
# 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))
- assert_raises(TypeError, operator.index, np.True_)
+ assert_warns(DeprecationWarning, operator.index, np.True_)
assert_raises(TypeError, np.take, args=(a, [0], False))
def test_boolean_indexing_weirdness(self):