thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

recarray scalars are not swapped on assignment (Trac #2185) #5975

Closed numpy-gitbot closed 12 years ago

numpy-gitbot commented 12 years ago

Original ticket http://projects.scipy.org/numpy/ticket/2185 on 2012-07-14 by trac user mbyt, assigned to unknown.

Hello,

numpy seems to not swap the byte order when assigning scalars in record arrays:

#!python
>>> import numpy as np
>>> 
>>> dt = np.dtype([
...    ('head', '>u4'),
...    ('data', '>u4', 2),
... ])
>>> buf = np.recarray(1, dtype=dt)
>>> buf[0]['head'] = 1
>>> buf[0]['data'][:] = [1,1]
>>> 
>>> h = buf[0]['head']
>>> d = buf[0]['data'][0]
>>> buf[0]['head'] = h
>>> buf[0]['data'][0] = d
>>> print buf, '\n', h.dtype.byteorder, d.dtype.byteorder
[(16777216L, array([1, 1], dtype=uint32))] 
= =

The byte order of both, h and d is native. However, when reassigning the scalar head in the recarray to h, the byte order is not swapped and h gets wrapped around to 16777216L (should be 1). Interestingly, the same is ok with an element of a vector (d stays 1, thus is swapped).

This behavior is the same on windows 32bit, python 2.7.4, numpy 1.6.2. and on linux 32bit, python 2.6.6, numpy 1.4.1.

Keep up the good work and cheers,[[BR]] Moritz

numpy-gitbot commented 12 years ago

Attachment added by trac user seberg on 2012-08-08: 0001-Fix-of-issue-with-scalars-in-np.choose-np.where.patch

numpy-gitbot commented 12 years ago

trac user seberg wrote on 2012-08-08

I think this is comes down to the same problem as https://github.com/numpy/numpy/issues/369 I am not quite sure if this is the right way to fix the issue though, but it does seem to fix it and my guess is that it is at least the correct place to fix it...

numpy-gitbot commented 12 years ago

trac user ocertik wrote on 2012-08-31

This is now fixed by: https://github.com/numpy/numpy/pull/395

numpy-gitbot commented 12 years ago

trac user ocertik wrote on 2012-08-31

PR was merged.