-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Inconsistent array assignment for structured arrays #3126
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
Comments
Also possibly #2599. After any fix for this issue other issues involving assignment should be checked. |
@charris I tried to fix this. The difference between a field assigned with a x[0]['field'] = np.ones(10, dtype='i4') calls
x[0]['field'][:] = np.ones(10, dtype='i4') calls
All I did in 14b6ff1 is to ensure, that for the first case no array is but a scalar is assigned. I added a corresponding test. This change resolves this ticket (#3126) and #3561. Any comments, better ideas, ...? |
Raising an error for non supported operations. Also adapting related statement in test. Resolves numpy#3126 and numpy#3561.
Hmm, following your example
I'm thinking it should only be allowed to assign |
sorry, took some time... As suggested, I sent a post: http://mail.scipy.org/pipermail/numpy-discussion/2014-April/069802.html. |
@charris looks like no one actively has something against the above suggestion on the list:
How can we proceed? |
Hmm, I need to think about this a bit more. Usually Python assignments are by reference, but numpy is a bit different in that you can do |
should we still consider this for 1.9, there are a bunch of linked bugs. |
There is a PR for this, so 1.9 would be good. It's long enough ago that the PR needs another review. |
Don't see any reason this would be a 1.9 blocker, though if the PR sneaks @charris: I'm sorry, what's the question? The behaviour here does seem On Fri, Jul 18, 2014 at 10:27 PM, Julian Taylor notifications@github.com
Nathaniel J. Smith |
It means I don't recall exactly what the state of the PR is, in particular apropos my comments may 30. I don't think it is a blocker as there are workarounds. |
@charris The suggestion was that the following syntay is OK:
While Currently The main enhancement I see in the PR is that the unsuccessful assignment is reported and not silently passed --- which will just help a lot in tracing down errors. |
I still have the impression that allowing the subarray assignment and On Mon, Dec 29, 2014 at 9:15 PM, mbyt notifications@github.com wrote:
Nathaniel J. Smith |
Thanks for the update. Regarding the "subarray assignment", one could also argue: In analogy to dict, that a) item assignment keeps the address / memory of the list, where as b) a direct assignment of "data" (the subarray assignment) will create a new address / memory. The option b) (create a new address) makes no sense for structured numpy arrays (which own all their data). Therefore, we raise an error --- also in order to effectively highlight the difference.
But I am sure that there are also good arguments in favor for allowing subarray assignment... Please let me know whenever I can do something to keep the ball rolling. |
Just merged again the master into the pull request related to this ticket #4556 mbyt@a8a1fc5. Travis still passes OK. #3561, which is basically a duplicate of this issue is also resolved through this pull request. I really would like to get this into the next numpy release / 1.10 --- it's just a 15 line change of production code. Is there anything I can do? |
This commit modifiesvoidtype_get/setfield to that they call the ndarray get/setfield. This solves bugs related to void-scalar assignment. This fixes issues numpy#3126, numpy#3561.
This bug was fixed sometime between numpy 1.9.2 (the OSG's version) and 1.11.1 (the current version). See numpy/numpy#3126.
When assigning arrays inside structured arrays without a left sided
[:]
, only the first element gets actually assigned. This is shown in the following code snippet, where a structured array is initialized with zeros, and then filled by assignment of an array, and the assignment of a structured array. The assignment of the array only assigns the first value, where the assignment of the structured array assigns all values:The expected result is that all elements of
x[0]['field']
are 1.However,
x[0]['field']
"recognizes" some part of the assigned array, as it will complain about broadcasting problems for wrong sizes:As mentioned in the beginning, adding
[:]
on the left side (In [6]) will correctly set all elements to 1. If the shown assignment is not allowed, I would have expected that an exception gets raised?The text was updated successfully, but these errors were encountered: