# [Numpy-tickets] [NumPy] #319: Setting a column in a recarray from another recarray corrupts data

NumPy numpy-tickets at scipy.net
Thu Oct 5 07:19:42 CDT 2006

```#319: Setting a column in a recarray from another recarray corrupts data
--------------------+-------------------------------------------------------
Reporter:  faltet  |       Owner:  somebody
Type:  defect  |      Status:  new
Priority:  normal  |   Milestone:
Component:  Other   |     Version:  devel
Severity:  normal  |    Keywords:
--------------------+-------------------------------------------------------
The next code snipped shows the problem (sorry but I haven't able to
simplify it more than it is now):

{{{
import numpy

rows = [ ([3, 2], (6j, 6.0, ('nn', [6j, 4j], [6.0, 4.0], [1L, 2L]), 'NN',
8), 'cc', ('NN', 6j), [[6.0, 4.0], [6.0, 4.0]], 8),
([4, 3], (7j, 7.0, ('oo', [7j, 5j], [7.0, 5.0], [2L, 1L]), 'OO',
9), 'dd', ('OO', 7j), [[7.0, 5.0], [7.0, 5.0]], 9)]

descr1 = [('x', '<i4', (2,)), ('Info', [('value', '<c16'), ('y2', '<f8'),
('Info2', [('name', '|S2'), ('value', '<c16', (2,)), ('y3', '<f8', (2,)),
('z3', '<u4', (2,))]), ('name', '|S2'), ('z2', '|u1')]), ('color', '|S2'),
('info', [('Name', '|S2'), ('Value', '<c16')]), ('y', '<f8', (2, 2)),
('z', '|u1')]

descr2 = [('value', '1c16'), ('y2', '1f8'), ('Info2', [('name', '1a2'),
('value', '(2,)c16'), ('y3', '(2,)f8'), ('z3', '(2,)u4')]), ('name',
'1a2'), ('z2', '1u1')]

ra1 = numpy.array(rows, dtype=descr1)
ra4 = ra1.copy()
print "ra1(orig)-->", ra1
ra2 = ra1['Info']
ra3 = numpy.rec.array(ra2, dtype=descr2)
# ra1['Info'] = ra2  # this works
ra1['Info'] = ra3    # this don't
print "ra1(final)-->", ra1

assert numpy.all(ra1 == ra4)

}}}

the output for my machine is:

{{{
ra1(orig)--> [ ([3, 2], (6j, 6.0, ('nn', [6j, 4j], [6.0, 4.0], [1L, 2L]),
'NN', 8), 'cc', ('NN', 6j), [[6.0, 4.0], [6.0, 4.0]], 8)
([4, 3], (7j, 7.0, ('oo', [7j, 5j], [7.0, 5.0], [2L, 1L]), 'OO', 9),
'dd', ('OO', 7j), [[7.0, 5.0], [7.0, 5.0]], 9)]
ra1(final)--> [ ([3, 2], (6j, 6.0, ('nn', [6j, 4j], [6.0, 4.0], [1L, 2L]),
'NN', 8), '', ('', 6j), [[6.0, 4.0], [6.0, 4.0]], 8)
([4, 3], (7j, 7.0, ('oo', [7j, 5j], [7.0, 5.0], [2L, 1L]), 'OO', 9),
'dd', ('OO', 7j), [[7.0, 5.0], [7.0, 5.0]], 9)]
Traceback (most recent call last):
File "prova4.py", line 33, in ?
assert numpy.all(ra1 == ra4)
AssertionError

}}}

it seems that there is a bizarre effect in creating the recarray using
rec.array.

--
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/319>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
```