diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2020-03-23 09:55:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-23 09:55:11 -0500 |
commit | 9ae4a0d1ebc52a556ed13248172e8280ad9fc6bd (patch) | |
tree | 71c37df0211023fbe54604c6bb36f815598d4d10 | |
parent | ad0049026f4afa5d6e8312c1a46b3777be396104 (diff) | |
parent | 849756ff1582ad46d14b7ff621a6e524337304f9 (diff) | |
download | numpy-9ae4a0d1ebc52a556ed13248172e8280ad9fc6bd.tar.gz |
Merge pull request #15805 from eric-wieser/expired-insert-delete-TypeError
DEP: Forbid passing non-integral index arrays to `insert` and `delete`
-rw-r--r-- | doc/release/upcoming_changes/15805.expired.rst | 6 | ||||
-rw-r--r-- | numpy/lib/function_base.py | 15 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 12 |
3 files changed, 18 insertions, 15 deletions
diff --git a/doc/release/upcoming_changes/15805.expired.rst b/doc/release/upcoming_changes/15805.expired.rst new file mode 100644 index 000000000..d317e98b8 --- /dev/null +++ b/doc/release/upcoming_changes/15805.expired.rst @@ -0,0 +1,6 @@ +`numpy.insert` and `numpy.delete` no longer accept non-integral indices +----------------------------------------------------------------------- +This concludes a deprecation from 1.9, where sequences of non-integers indices +were allowed and cast to integers. Now passing sequences of non-integral +indices raises ``IndexError``, just like it does when passing a single +non-integral scalar. diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 1c67f7c99..d39ee63b6 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -4369,14 +4369,6 @@ def delete(arr, obj, axis=None): else: if obj.size == 0 and not isinstance(_obj, np.ndarray): obj = obj.astype(intp) - if not np.can_cast(obj, intp, 'same_kind'): - # obj.size = 1 special case always failed and would just - # give superfluous warnings. - # 2013-09-24, 1.9 - warnings.warn( - "using a non-integer array as obj in delete will result in an " - "error in the future", DeprecationWarning, stacklevel=3) - obj = obj.astype(intp) keep = ones(N, dtype=bool) # Test if there are out of bound indices, this is deprecated @@ -4590,13 +4582,6 @@ def insert(arr, obj, values, axis=None): # Can safely cast the empty list to intp indices = indices.astype(intp) - if not np.can_cast(indices, intp, 'same_kind'): - # 2013-09-24, 1.9 - warnings.warn( - "using a non-integer array as obj in insert will result in an " - "error in the future", DeprecationWarning, stacklevel=3) - indices = indices.astype(intp) - indices[indices < 0] += N numnew = len(indices) diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 860cf452b..a5988a719 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -544,6 +544,12 @@ class TestInsert: b = np.insert(a, [0, 2], val) assert_array_equal(b[[0, 3]], np.array(val, dtype=b.dtype)) + def test_index_floats(self): + with pytest.raises(IndexError): + np.insert([0, 1, 2], np.array([1.0, 2.0]), [10, 20]) + with pytest.raises(IndexError): + np.insert([0, 1, 2], np.array([], dtype=float), []) + class TestAmax: @@ -868,6 +874,12 @@ class TestDelete: assert_equal(m.flags.c_contiguous, k.flags.c_contiguous) assert_equal(m.flags.f_contiguous, k.flags.f_contiguous) + def test_index_floats(self): + with pytest.raises(IndexError): + np.delete([0, 1, 2], np.array([1.0, 2.0])) + with pytest.raises(IndexError): + np.delete([0, 1, 2], np.array([], dtype=float)) + class TestGradient: |