[Numpy-svn] r5627 - in trunk/numpy/core: src tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Sun Aug 10 16:19:59 EDT 2008
Author: oliphant
Date: 2008-08-10 15:19:58 -0500 (Sun, 10 Aug 2008)
New Revision: 5627
Modified:
trunk/numpy/core/src/arrayobject.c
trunk/numpy/core/tests/test_regression.py
Log:
Fix ticket #674.
Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c 2008-08-10 20:05:49 UTC (rev 5626)
+++ trunk/numpy/core/src/arrayobject.c 2008-08-10 20:19:58 UTC (rev 5627)
@@ -11145,7 +11145,8 @@
/* 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 @@
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_DelItem(self->fields, key);
PyDict_SetItem(self->fields, new_key, item);
- PyDict_DelItem(self->fields, key);
+ Py_DECREF(item); /* self->fields now holds reference */
}
/* Replace names */
Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py 2008-08-10 20:05:49 UTC (rev 5626)
+++ trunk/numpy/core/tests/test_regression.py 2008-08-10 20:19:58 UTC (rev 5627)
@@ -1174,6 +1174,15 @@
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()
More information about the Numpy-svn
mailing list