[Numpy-discussion] issue #1431 accessing multiple fields in a recarray

sam tygier samtygier@yahoo.co...
Sun Jun 27 07:26:50 CDT 2010


Hello

A while ago there was a discussion about field order when accessing recarrays. eg:

>>> x = np.array([(1.5,2.5,(1.0,2.0)),(3.,4.,(4.,5.)),(1.,3.,(2.,6.))],
         dtype=[('x','f4'),('y',np.float32),('value','f4',(2,2))])
>>> x[['x','y']]
array([(1.5, 2.5), (3.0, 4.0), (1.0, 3.0)],
      dtype=[('x', '<f4'), ('y', '<f4')])
>>> x[['y','x']]
array([(1.5, 2.5), (3.0, 4.0), (1.0, 3.0)],
      dtype=[('x', '<f4'), ('y', '<f4')])

http://thread.gmane.org/gmane.comp.python.numeric.general/36933

There is a bug at http://projects.scipy.org/numpy/ticket/1431

The fix is very simple, but there was some worry that some existing code may require the broken behavior. eg some code may ask for:
x[['y','x']]
and expect the result to have 'x' as the first column in the result.

I suspect that code like this is rare (it could be easily changed to x[['x','y']] if thats what is really wanted).

I think the correct way to proceed is probably to raise a DeprecationWarning for code that it requiring the broken behavior. The bug has a patch to implement this. Then in a future version the patch to fix it could be applied.

Thanks

Sam



More information about the NumPy-Discussion mailing list