summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src6
-rw-r--r--numpy/core/tests/test_multiarray.py4
2 files changed, 10 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index 6f3637cc1..0bd367567 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -2185,6 +2185,12 @@ voidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val)
return -1;
}
+ if (!val) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot delete scalar field");
+ return -1;
+ }
+
#if defined(NPY_PY3K)
if (PyUString_Check(ind)) {
#else
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index cb02c3666..9f333a4a2 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -3732,6 +3732,10 @@ def test_flat_element_deletion():
except:
raise AssertionError
+def test_scalar_element_deletion():
+ a = np.zeros(2, dtype=[('x', 'int'), ('y', 'int')])
+ assert_raises(ValueError, a[0].__delitem__, 'x')
+
class TestMemEventHook(TestCase):
def test_mem_seteventhook(self):
# The actual tests are within the C code in