[Numpy-tickets] [NumPy] #674: Impossible to rename object fields

NumPy numpy-tickets@scipy....
Thu Feb 28 14:52:08 CST 2008


#674: Impossible to rename object fields
------------------------+---------------------------------------------------
 Reporter:  sameer      |       Owner:  somebody
     Type:  defect      |      Status:  new     
 Priority:  normal      |   Milestone:  1.0.5   
Component:  numpy.core  |     Version:  none    
 Severity:  minor       |    Keywords:          
------------------------+---------------------------------------------------
 It is not possible to change the name of a field if it is an object array.

 Please see the code block below or reference the discussion at
 http://projects.scipy.org/pipermail/numpy-
 discussion/2008-February/031654.html

 {{{
  In [1]: from numpy import *

  In [2]: olddt = dtype([('foo', '|O4'), ('bar', float)])

  In [3]: a = zeros(10, olddt)

  In [4]: a
  Out[4]:
  array([(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0),
         (0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)],
        dtype=[('foo', '|O4'), ('bar', '<f8')])

  In [5]: newdt = dtype([('notfoo', '|O4'), ('notbar', float)])

  In [6]: b = a.view(newdt)
 ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call
 last)

  /home/titan/sameer/projects/<ipython console>

  TypeError: Cannot change data-type for object array.

 }}}

 Also, it would be useful to have an API to rename record array fields. The
 current method of creating a new dtype and calling the view method of the
 record array seems like too much of a hack.

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


More information about the Numpy-tickets mailing list