You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
record array is made up of numpy.void, not numpy.record #271
If I manually create a record array, from say, a list of tuples, I can individually pull out "rows" of this and they are of type numpy.record. This means I can do things, such as:
arr[0].price
and it works.
If I get an array from table.read, or read_where, and then do a .view(np.recarray) I get a record array that looks correct at first glance, but is actually made up of numpy.void objects. And the above code fails because arr[0] is a numpy.void and I cannot call .price on it.
From a users perspective, you shouldn't have seemingly identical looking objects (np.recarray) that behave differently depending on how they were created. I suspect this is a NumPy bug, but interested in your thoughts seeing as it is a fairly common use-case for PyTables.
Now, I realise the example above is NumPy only, but the same type of object, a sort of 'fake recarray', gets returned from table.read, so wanted to see if you guys were aware of this
Hi @potyt, I was not aware of this behavior. (I almost never use recarrays _.) But this is not surprising. Reading data out of Tables returns numpy.ndarrays. After reading, I would expect these to perform exactly the same way as the pure numpy example above. I think that you should report this to numpy. Since it is outside the scope of PyTables, would you mind if I closed this as invalid?
Indeed, been making these sorts of compromises for a while, but on the occasion that you need to row-by-row iterator through an array, rather than access the data column-wise, this isn't so easy (or efficient I would think, as you would index into the overall array twice with something like arr.price[0] > arr.limit[0] rather than row.price > row.limit
Not a big deal for one simple comparison, but if you are picking out a lot of these columns, and acting on their values in a loop that runs a lot, it could add up!?
More importantly, it also means keeping track of your own row index(es), which could introduce the odd bug, reduces the readability of the code and takes away some of the elegance of the row-based approach.
Activity
scopatz commentedon Aug 5, 2013
Don't you need to do
.view(type=np.recarry)?potyt commentedon Aug 6, 2013
Exactly, that's what I am asking about:
Now, I realise the example above is NumPy only, but the same type of object, a sort of 'fake recarray', gets returned from table.read, so wanted to see if you guys were aware of this
scopatz commentedon Aug 6, 2013
Hi @potyt, I was not aware of this behavior. (I almost never use recarrays
_.) But this is not surprising. Reading data out of Tables returnsnumpy.ndarrays. After reading, I would expect these to perform exactly the same way as the pure numpy example above. I think that you should report this to numpy. Since it is outside the scope of PyTables, would you mind if I closed this as invalid?potyt commentedon Aug 6, 2013
Sure, I'll raise this on a NumPy list, ah, it's on github too...
avalentino commentedon Aug 6, 2013
Just for the record, a simple workaround could be to swap the order of operations:
arr.price[0]instead ofarr[0].pricepotyt commentedon Aug 6, 2013
Indeed, been making these sorts of compromises for a while, but on the occasion that you need to row-by-row iterator through an array, rather than access the data column-wise, this isn't so easy (or efficient I would think, as you would index into the overall array twice with something like
arr.price[0] > arr.limit[0]rather thanrow.price > row.limitNot a big deal for one simple comparison, but if you are picking out a lot of these columns, and acting on their values in a loop that runs a lot, it could add up!?
More importantly, it also means keeping track of your own row index(es), which could introduce the odd bug, reduces the readability of the code and takes away some of the elegance of the row-based approach.
Thanks for the v.quick responses btw.
FrancescAlted commentedon Apr 27, 2015
Out of scope of PyTables.