summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2018-06-17 17:09:08 -0600
committerGitHub <noreply@github.com>2018-06-17 17:09:08 -0600
commit44cfca844f043722906a9b2932a4ba03dce15c75 (patch)
tree6ce9d356b4aed444232b0ca96b04a26cba7819ab
parent621d48d772c9a1c69788cdb68049b729021ba14b (diff)
parent13beece29ccbaa96fd4b811c3a185dd6ccaf5899 (diff)
downloadnumpy-44cfca844f043722906a9b2932a4ba03dce15c75.tar.gz
Merge pull request #11366 from eric-wieser/bad-warning
BUG/TST: String indexing should just fail, not emit a futurewarning
-rw-r--r--numpy/core/src/multiarray/mapping.c3
-rw-r--r--numpy/core/tests/test_indexing.py29
2 files changed, 19 insertions, 13 deletions
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c
index 82a0683f9..46ff78b9c 100644
--- a/numpy/core/src/multiarray/mapping.c
+++ b/numpy/core/src/multiarray/mapping.c
@@ -233,7 +233,8 @@ unpack_indices(PyObject *index, PyObject **result, npy_intp result_n)
|| index == Py_None
|| PySlice_Check(index)
|| PyArray_Check(index)
- || !PySequence_Check(index)) {
+ || !PySequence_Check(index)
+ || PyBaseString_Check(index)) {
return unpack_scalar(index, result, result_n);
}
diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py
index 88f5deabc..cbcd3e994 100644
--- a/numpy/core/tests/test_indexing.py
+++ b/numpy/core/tests/test_indexing.py
@@ -833,7 +833,10 @@ class TestMultiIndexingAutomated(object):
# is not safe. It rejects np.array([1., 2.]) but not
# [1., 2.] as index (same for ie. np.take).
# (Note the importance of empty lists if changing this here)
- indx = np.array(indx, dtype=np.intp)
+ try:
+ indx = np.array(indx, dtype=np.intp)
+ except ValueError:
+ raise IndexError
in_indices[i] = indx
elif indx.dtype.kind != 'b' and indx.dtype.kind != 'i':
raise IndexError('arrays used as indices must be of '
@@ -986,9 +989,13 @@ class TestMultiIndexingAutomated(object):
# Maybe never happens...
raise ValueError
arr = arr.take(mi.ravel(), axis=ax)
- arr = arr.reshape((arr.shape[:ax]
- + mi.shape
- + arr.shape[ax+1:]))
+ try:
+ arr = arr.reshape((arr.shape[:ax]
+ + mi.shape
+ + arr.shape[ax+1:]))
+ except ValueError:
+ # too many dimensions, probably
+ raise IndexError
ax += mi.ndim
continue
@@ -1014,8 +1021,8 @@ class TestMultiIndexingAutomated(object):
except Exception as e:
if HAS_REFCOUNT:
prev_refcount = sys.getrefcount(arr)
- assert_raises(Exception, arr.__getitem__, index)
- assert_raises(Exception, arr.__setitem__, index, 0)
+ assert_raises(type(e), arr.__getitem__, index)
+ assert_raises(type(e), arr.__setitem__, index, 0)
if HAS_REFCOUNT:
assert_equal(prev_refcount, sys.getrefcount(arr))
return
@@ -1038,8 +1045,8 @@ class TestMultiIndexingAutomated(object):
except Exception as e:
if HAS_REFCOUNT:
prev_refcount = sys.getrefcount(arr)
- assert_raises(Exception, arr.__getitem__, index)
- assert_raises(Exception, arr.__setitem__, index, 0)
+ assert_raises(type(e), arr.__getitem__, index)
+ assert_raises(type(e), arr.__setitem__, index, 0)
if HAS_REFCOUNT:
assert_equal(prev_refcount, sys.getrefcount(arr))
return
@@ -1127,10 +1134,8 @@ class TestMultiIndexingAutomated(object):
def test_1d(self):
a = np.arange(10)
- with warnings.catch_warnings():
- warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)
- for index in self.complex_indices:
- self._check_single_index(a, index)
+ for index in self.complex_indices:
+ self._check_single_index(a, index)
class TestFloatNonIntegerArgument(object):
"""