New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
record array is made up of numpy.void, not numpy.record #3581
Comments
Just wondering if anyone is in a position to confirm/deny this as an issue? |
Bueller? |
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... |
This is a modification to the dtype str and repr functions what helps solve numpy#3581. I discussed it on the mailing list in a message "Re: structured arrays, recarrays, and record arrays" on Jan 19 2015. I didn't get any replies, but hopefully that merely means "no opinion" rather than "bad idea". What it does: For structured arrays, if the dtype is not np.void then print the dtype as `(base_dtype, dtype)`. New Behavior: >>> a = np.array([(1,'ABC'), (2, "DEF")], dtype=[('foo', int), ('bar', 'S4')]) >>> np.rec.array(a) rec.array([(1, 'ABC'), (2, 'DEF')], dtype=(numpy.record, [('foo', '<i8'), ('bar', 'S4')])) >>> a.view(np.recarray) rec.array([(1, 'ABC'), (2, 'DEF')], dtype=[('foo', '<i8'), ('bar', 'S4')])
Anything that could be done to fix this issue would be appreciated... recarrays are powerful but this issue makes them tricky to use. |
Does #5921 fix this issue, or is it not quite the same? |
I just checked, and this doesn't appear to be fixed. I'll take a look though. |
Although it's not clear to me why |
@embray
I discussed it in #5523. Also, I added new docs for record arrays which explain what I've done in #5482, which aren't visible in the online docs yet. Improvements welcome. |
Also, I consider this issue fixed, as explained in #5523. In the example code, |
You might consider this issue fixed, but highly related #4443 is still broken. Just tested against the issue in that example and the others I considered dupes. |
@nevion ha, I didn't mean to sound so final. But #4443 is working as I expect. If you read the new docs I wrote in #5482 (here) The current issue #3581 arose because their reprs were identical, which was confusing. So in #5523 I made sure their reprs are different, to make it clear to the user that they are different. I couldn't think of a better fix, but if there is one that would be great. The problem is that there are two separate aspects of record arrays: 1. They have type I think that As I note in the docs you can get a "true" record array using a view by doing
|
Okay, so I guess the current behavior could be considered consistent, if confusing. In any case it's maybe not worth worrying about since, last I heard, recarrays are all but deprecated? |
Recarrays seem pretty widely used, but have never been 'official', which may be an oversight. I'm not sure what the long term plan for them should be. Feedback welcome, and maybe a post on the mailing list for discussion. |
Sorry to be late in this, but I'm slightly confused why |
@mhvk when I wrote those PRs I didn't know about
to np.recarray works. Is that the right way to change the dtype? Edit: I spoke too soon that doesn't work |
@ahaldane - yes, in principle, though be careful that you can get into
This way nothing gets changed when initializing or slicing a Though in practice, since for initialization or slicing the [1] http://docs.scipy.org/doc/numpy/user/basics.subclassing.html#the-role-of-array-finalize |
@mhvk I see. I think I got it to work (I was missing
then I see it works:
I'll submit a PR. Good thing this came up for discussion again! |
@mhvk I was thinking this as well. I guess I figured if you take a view with |
@abalkin would be good to have a PR for this. Does defining |
I raised this previously on the PyTables issue list, but it they have asked me to transfer to numpy. (PyTables/PyTables#271)
Any reason why .view can't return record arrays instead of sort of fake record arrays, or voidarrays? Is there a cast missing in the code somewhere?
The text was updated successfully, but these errors were encountered: