summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/conversion_utils.c11
-rw-r--r--numpy/core/tests/test_deprecations.py4
2 files changed, 14 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c
index a177e49dd..79093467f 100644
--- a/numpy/core/src/multiarray/conversion_utils.c
+++ b/numpy/core/src/multiarray/conversion_utils.c
@@ -698,7 +698,7 @@ PyArray_PyIntAsIntp(PyObject *o)
return -1;
}
- /* Be a bit stricter and not allow bools */
+ /* Be a bit stricter and not allow bools, np.bool_ is handled later */
if (PyBool_Check(o)) {
if (DEPRECATE("using a boolean instead of an integer"
" will result in an error in the future") < 0) {
@@ -730,6 +730,15 @@ PyArray_PyIntAsIntp(PyObject *o)
#endif
return (npy_intp)long_value;
}
+
+ /* Disallow numpy.bool_. Boolean arrays do not currently support index. */
+ if (PyArray_IsScalar(o, Bool)) {
+ 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
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index 2b9fcdb69..2bedbca09 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -255,6 +255,10 @@ class TestBooleanArgumentDeprecation(_DeprecationTestCase):
a = np.array([[[1]]])
self.assert_deprecated(np.reshape, args=(a, (True, -1)))
+ self.assert_deprecated(np.reshape, args=(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)