summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2020-03-24 13:30:19 +0000
committerGitHub <noreply@github.com>2020-03-24 13:30:19 +0000
commit7d0b3efe4b38fb5b5ba7367741b55d7655037ad0 (patch)
tree52510609bfb3698af07468c65efff570ddc5d999
parentb3f41eeafd2708a6b519cf3c7ba3576dfa1cc5b3 (diff)
parentf0e37e8088e55307ad33791a03cb3989f1b8118c (diff)
downloadnumpy-7d0b3efe4b38fb5b5ba7367741b55d7655037ad0.tar.gz
Merge pull request #15802 from eric-wieser/simplify-insert
DEP: Make `np.insert` and `np.delete` on 0d arrays with an axis an error
-rw-r--r--doc/release/upcoming_changes/15802.expired.rst9
-rw-r--r--numpy/lib/function_base.py20
-rw-r--r--numpy/lib/tests/test_function_base.py17
3 files changed, 17 insertions, 29 deletions
diff --git a/doc/release/upcoming_changes/15802.expired.rst b/doc/release/upcoming_changes/15802.expired.rst
new file mode 100644
index 000000000..1a1b373a7
--- /dev/null
+++ b/doc/release/upcoming_changes/15802.expired.rst
@@ -0,0 +1,9 @@
+`numpy.insert` and `numpy.delete` can no longer be passed an axis on 0d arrays
+------------------------------------------------------------------------------
+This concludes a deprecation from 1.9, where when an ``axis`` argument was
+passed to a call to `~numpy.insert` and `~numpy.delete` on a 0d array, the
+``axis`` and ``obj`` argument and indices would be completely ignored.
+In these cases, ``insert(arr, "nonsense", 42, axis=0)`` would actually overwrite the
+entire array, while ``delete(arr, "nonsense", axis=0)`` would be ``arr.copy()``
+
+Now passing ``axis`` on a 0d array raises `~numpy.AxisError`.
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index a49c34741..7211b68cf 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -4273,15 +4273,6 @@ def delete(arr, obj, axis=None):
# needed for np.matrix, which is still not 1d after being ravelled
ndim = arr.ndim
axis = ndim - 1
- elif ndim == 0:
- # 2013-09-24, 1.9
- warnings.warn(
- "in the future the special handling of scalars will be removed "
- "from delete and raise an error", DeprecationWarning, stacklevel=3)
- if wrap:
- return wrap(arr)
- else:
- return arr.copy(order=arrorder)
else:
axis = normalize_axis_index(axis, ndim)
@@ -4490,17 +4481,6 @@ def insert(arr, obj, values, axis=None):
# needed for np.matrix, which is still not 1d after being ravelled
ndim = arr.ndim
axis = ndim - 1
- elif ndim == 0:
- # 2013-09-24, 1.9
- warnings.warn(
- "in the future the special handling of scalars will be removed "
- "from insert and raise an error", DeprecationWarning, stacklevel=3)
- arr = arr.copy(order=arrorder)
- arr[...] = values
- if wrap:
- return wrap(arr)
- else:
- return arr
else:
axis = normalize_axis_index(axis, ndim)
slobj = [slice(None)]*ndim
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 04b280038..fb10205d4 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -509,12 +509,11 @@ class TestInsert:
insert(a, 1, a[:, 2, :], axis=1))
def test_0d(self):
- # This is an error in the future
a = np.array(1)
- with warnings.catch_warnings(record=True) as w:
- warnings.filterwarnings('always', '', DeprecationWarning)
- assert_equal(insert(a, [], 2, axis=0), np.array(2))
- assert_(w[0].category is DeprecationWarning)
+ with pytest.raises(np.AxisError):
+ insert(a, [], 2, axis=0)
+ with pytest.raises(TypeError):
+ insert(a, [], 2, axis="nonsense")
def test_subclass(self):
class SubClass(np.ndarray):
@@ -852,10 +851,10 @@ class TestDelete:
def test_0d(self):
a = np.array(1)
- with warnings.catch_warnings(record=True) as w:
- warnings.filterwarnings('always', '', DeprecationWarning)
- assert_equal(delete(a, [], axis=0), a)
- assert_(w[0].category is DeprecationWarning)
+ with pytest.raises(np.AxisError):
+ delete(a, [], axis=0)
+ with pytest.raises(TypeError):
+ delete(a, [], axis="nonsense")
def test_subclass(self):
class SubClass(np.ndarray):