[NumPy-Tickets] [NumPy] #2006: Why does recarray assignment fail: "cannot call setfield on an object array"?
NumPy Trac
numpy-tickets@scipy....
Fri Dec 23 13:31:02 CST 2011
#2006: Why does recarray assignment fail: "cannot call setfield on an object
array"?
----------------------------------------------------------+-----------------
Reporter: kevin000 | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: Unscheduled
Component: numpy.core | Version: devel
Keywords: recarray setfield object array runtime error |
----------------------------------------------------------+-----------------
Using a recarray with member assignment fails if any column uses the
object data type. I don't understand why this fails, especially since the
dictionary style assignment works.
# Brief example showing what recarray assignments succeed or fail
import numpy as np
# recarray with integer datatypes
dt = np.dtype([('foo', 'i8'), ('bar', 'i8')])
r = np.zeros((1,3), dtype=dt).view(np.recarray)
r['foo'] = np.array([1, 2, 3]) # OK
r.foo = np.array([1, 2, 3]) # OK
# recarray with an object datatype
dt = np.dtype([('foo', 'i8'), ('bar', 'O8')])
r = np.zeros((1,3), dtype=dt).view(np.recarray)
r['foo'] = np.array([1, 2, 3]) # OK
r.foo = np.array([1, 2, 3]) # RuntimeError
For the relevant C code search for "cannot call setfield on an object
array" in this file:
https://github.com/numpy/numpy/blob/master/numpy/core/src/multiarray/methods.c
Thanks!
Kevin
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/2006>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list