diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2020-03-22 14:28:06 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2020-03-22 19:03:35 +0000 |
commit | f0e37e8088e55307ad33791a03cb3989f1b8118c (patch) | |
tree | 16c8362d6152fec120d6632bb7249b1c448f6b80 /numpy/lib | |
parent | 90e644e7c668d52155e9a07b1032e71974e3dc7d (diff) | |
download | numpy-f0e37e8088e55307ad33791a03cb3989f1b8118c.tar.gz |
DEP: Make `np.insert` and `np.delete` on 0d arrays with an axis an error
Before this change, the following code worked:
```
>>> some_0d = np.array(1)
>>> np.insert(some_0d, "some nonsense", 10, axis=0)
array(10)
>>> np.insert(some_0d, "some nonsense", 42, axis="some nonsense")
array(42)
```
Now these raise AxisError and TypeError, respectively.
`delete` is exactly the same.
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/function_base.py | 20 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 17 |
2 files changed, 8 insertions, 29 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 1c67f7c99..5b2dec1c1 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) @@ -4515,17 +4506,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 860cf452b..65bc9f1ec 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): @@ -843,10 +842,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): |