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 #3581
bump for this little annoyer - I can confirm this bug and it regularly affects me... accessing structure arrays with ['fieldname'] as the longtime workaround just looks so wrong to boot...
@mhvk when I wrote those PRs I didn't know about __array_finalize__, but now I do and I was just thinking about that this morning. It looks like adding
@ahaldane - yes, in principle, though be careful that you can get into __array_finalize__ via different routes [1]. You may want to do something like
def __array_finalize__(self, obj):
if obj is not None and type(obj) is not type(self):
self.dtype = dtype(record, obj.dtype)
This way nothing gets changed when initializing or slicing a recarray.
Though in practice, since for initialization or slicing the dtype is already correct, you could also just check whether self.dtype is correct and only change it if it is not.
@mhvk I was thinking this as well. I guess I figured if you take a view with type=np.recarray but not with dtype=(np.record, arr.dtype) then maybe it would be consistent. But I agree it's actually more consistent that recarray objects always return elements with np.record type, and your suggestion is exactly how that is done.
Activity
potyt commentedon Sep 16, 2013
Just wondering if anyone is in a position to confirm/deny this as an issue?
potyt commentedon May 1, 2014
Bueller?
Bueller?
nevion commentedon Oct 9, 2014
bump for this little annoyer - I can confirm this bug and it regularly affects me... accessing structure arrays with ['fieldname'] as the longtime workaround just looks so wrong to boot...
dalexander commentedon Jun 2, 2015
Anything that could be done to fix this issue would be appreciated... recarrays are powerful but this issue makes them tricky to use.
10 remaining items
ahaldane commentedon Jun 4, 2015
@mhvk when I wrote those PRs I didn't know about
__array_finalize__, but now I do and I was just thinking about that this morning. It looks like addingto np.recarray works. Is that the right way to change the dtype?
Edit: I spoke too soon that doesn't work
mhvk commentedon Jun 4, 2015
@ahaldane - yes, in principle, though be careful that you can get into
__array_finalize__via different routes [1]. You may want to do something likeThis way nothing gets changed when initializing or slicing a
recarray.Though in practice, since for initialization or slicing the
dtypeis already correct, you could also just check whetherself.dtypeis correct and only change it if it is not.[1] http://docs.scipy.org/doc/numpy/user/basics.subclassing.html#the-role-of-array-finalize
ahaldane commentedon Jun 4, 2015
@mhvk I see. I think I got it to work (I was missing
()) with this:then I see it works:
I'll submit a PR. Good thing this came up for discussion again!
mhvk commentedon Jun 4, 2015
@ahaldane - great! hope this solves @embray's issues too...
embray commentedon Jun 4, 2015
@mhvk I was thinking this as well. I guess I figured if you take a view with
type=np.recarraybut not withdtype=(np.record, arr.dtype)then maybe it would be consistent. But I agree it's actually more consistent thatrecarrayobjects always return elements withnp.recordtype, and your suggestion is exactly how that is done.charris commentedon Jun 5, 2015
@abalkin would be good to have a PR for this. Does defining
__array_finalize_arraysolve any of the problems for which there are other PRs?