summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2008-08-10 20:19:58 +0000
committerTravis Oliphant <oliphant@enthought.com>2008-08-10 20:19:58 +0000
commit7bb36be47c5a2e1b1d51a556eec99bf741c2ff75 (patch)
tree1f62840d777576817710f0119aa8999ff551fbc5
parent75c15c8c697eba656e333612821d44cdd46134fe (diff)
downloadnumpy-7bb36be47c5a2e1b1d51a556eec99bf741c2ff75.tar.gz
Fix ticket #674.
-rw-r--r--numpy/core/src/arrayobject.c7
-rw-r--r--numpy/core/tests/test_regression.py9
2 files changed, 14 insertions, 2 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 5b2390f03..fe789dee9 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -11145,7 +11145,8 @@ arraydescr_dealloc(PyArray_Descr *self)
/* we need to be careful about setting attributes because these
objects are pointed to by arrays that depend on them for interpreting
- data. Currently no attributes of dtype objects can be set.
+ data. Currently no attributes of data-type objects can be set
+ directly except names.
*/
static PyMemberDef arraydescr_members[] = {
{"type", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},
@@ -11403,9 +11404,11 @@ arraydescr_names_set(PyArray_Descr *self, PyObject *val)
key = PyTuple_GET_ITEM(self->names, i);
/* Borrowed reference to item */
item = PyDict_GetItem(self->fields, key);
+ Py_INCREF(item); /* Hold on to it even through DelItem */
new_key = PyTuple_GET_ITEM(new_names, i);
- PyDict_SetItem(self->fields, new_key, item);
PyDict_DelItem(self->fields, key);
+ PyDict_SetItem(self->fields, new_key, item);
+ Py_DECREF(item); /* self->fields now holds reference */
}
/* Replace names */
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 33d12b61c..b104b888c 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1174,6 +1174,15 @@ class TestRegression(TestCase):
want = np.array([-1+0j, -1+0j, 0+0j, 1+0j, 1+0j, 0+0j])
assert_equal(have, want)
+ def test_for_equal_names(self, level=rlevel):
+ """Ticket #674"""
+ dt = np.dtype([('foo', float), ('bar', float)])
+ a = np.zeros(10, dt)
+ b = list(a.dtype.names)
+ b[0] = "notfoo"
+ a.dtype.names = b
+ assert a.dtype.names[0] == "notfoo"
+ assert a.dtype.names[1] == "bar"
if __name__ == "__main__":
run_module_suite()