-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
Original ticket http://projects.scipy.org/numpy/ticket/2006 on 2011-12-23 by trac user kevin000, assigned to unknown.
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