Rename record array fields (with object arrays)

Hi, I'm having trouble renaming record array fields if they contain object arrays in them. I followed the solutions posted by Robert Kern and Stefan van der Walt (Thanks again) but it doesn't look like this method works in all cases. For reference: http://projects.scipy.org/pipermail/numpy-discussion/2008-February/031509.ht... 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. -- Sameer

Sameer DCosta wrote:
Hi,
I'm having trouble renaming record array fields if they contain object arrays in them. I followed the solutions posted by Robert Kern and Stefan van der Walt (Thanks again) but it doesn't look like this method works in all cases. For reference: http://projects.scipy.org/pipermail/numpy-discussion/2008-February/031509.ht...
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.
This looks like a bug. We are being a bit over-zealous in protecting you from getting access to pointers and in the process making it impossible to rename Object fields. Perhaps an actual field-renaming API (which would be relatively easy) is useful. -Travis O.

I think having a record array field renaming api is a good idea.. I was going to create a ticket for this, but I don't think I have permissions to do this. Can someone who has the permissions, please create it? Thanks. Sameer On Thu, Feb 28, 2008 at 10:48 AM, Travis E. Oliphant <oliphant@enthought.com> wrote:
Sameer DCosta wrote:
Hi,
I'm having trouble renaming record array fields if they contain object arrays in them. I followed the solutions posted by Robert Kern and Stefan van der Walt (Thanks again) but it doesn't look like this method works in all cases. For reference: http://projects.scipy.org/pipermail/numpy-discussion/2008-February/031509.ht...
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.
This looks like a bug. We are being a bit over-zealous in protecting you from getting access to pointers and in the process making it impossible to rename Object fields.
Perhaps an actual field-renaming API (which would be relatively easy) is useful.
-Travis O.

On Thu, Feb 28, 2008 at 2:00 PM, Sameer DCosta <sameerslists@gmail.com> wrote:
I think having a record array field renaming api is a good idea.. I was going to create a ticket for this, but I don't think I have permissions to do this. Can someone who has the permissions, please create it? Thanks.
Click on the "Register" link in the upper right-hand corner. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco

On Thu, Feb 28, 2008 at 2:11 PM, Robert Kern <robert.kern@gmail.com> wrote:
On Thu, Feb 28, 2008 at 2:00 PM, Sameer DCosta <sameerslists@gmail.com> wrote:
was going to create a ticket for this, but I don't think I have permissions to do this. Can someone who has the permissions, please create it? Thanks.
Click on the "Register" link in the upper right-hand corner.
Thanks I should have read the wiki page before posting to the list. However, here is the ticket. http://scipy.org/scipy/numpy/ticket/674 Sameer

Travis E. Oliphant wrote:
Sameer DCosta wrote:
Hi,
I'm having trouble renaming record array fields if they contain object arrays in them. I followed the solutions posted by Robert Kern and Stefan van der Walt (Thanks again) but it doesn't look like this method works in all cases. For reference: http://projects.scipy.org/pipermail/numpy-discussion/2008-February/031509.ht...
In [1]: from numpy import *
In [2]: olddt = dtype([('foo', '|O4'), ('bar', float)])
In [3]: a = zeros(10, olddt)
Can you try: olddt.names = ['notfoo', 'notbar'] on a recent SVN tree. This should now work.... -Travis
participants (3)
-
Robert Kern
-
Sameer DCosta
-
Travis E. Oliphant