summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/release/1.14.0-notes.rst6
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src9
-rw-r--r--numpy/core/tests/test_indexing.py1
3 files changed, 15 insertions, 1 deletions
diff --git a/doc/release/1.14.0-notes.rst b/doc/release/1.14.0-notes.rst
index 90dae9695..4f8f94850 100644
--- a/doc/release/1.14.0-notes.rst
+++ b/doc/release/1.14.0-notes.rst
@@ -21,6 +21,12 @@ New functions
Deprecations
============
+``np.bool_`` objects being used in place of integers
+---------------------------------------------------
+Previously ``operator.index(np.bool_)`` was legal, allowing constructs
+such as ``[1, 2, 3][np.True_]``. This was misleading, as it behaved differently
+from ``np.array([1, 2, 3])[np.True_]``. This behavior is deprecated.
+
* Truth testing on an empty array is deprecated. To check if an array is not
empty, use ``array.size > 0``.
* Calling ``np.bincount`` with ``minlength=None`` is deprecated - instead,
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index c92d835ed..87d29bf04 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -2845,7 +2845,14 @@ static PyNumberMethods @name@_arrtype_as_number;
static PyObject *
bool_index(PyObject *a)
{
- return PyInt_FromLong(PyArrayScalar_VAL(a, Bool));
+ 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 4c3bac529..7cfb81da7 100644
--- a/numpy/core/tests/test_indexing.py
+++ b/numpy/core/tests/test_indexing.py
@@ -1174,6 +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_warns(DeprecationWarning, operator.index, np.True_)
assert_raises(TypeError, np.take, args=(a, [0], False))
def test_boolean_indexing_weirdness(self):