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
When attempting to create a view of a indexed structured array, in order to create a a standard ndarray, the view method does not appropriately resize the output array. It appears to instead preserve the size of the full structured array.
I think this is a duplicate of the discussion in gh-13299, in that you expect the copy removes the unnecessary padding (and thus view to work). Although the truth is pretty complex with respect to view itself, since sometimes we may not want to remove all padding.
View has to work with the raw itemsize really probably, since otherwise it would need to absorb the dtype shape somehow? I could think about adding a warning if it views previously inaccessible data, but not sure that is a solution either.
I agree that this is similar. However, if you remove the copy you still get unexpected behavior. The view will return the full contents of the structured array if copy is removed. The behavior is unexpected since the array index occurs first in precedence.
I will also add that this seems to be a recent change to the behavior of numpy. I need to track down the exact version when this changed but the older version of numpy had correct behavior.
@degrootc no need to track it down, the view semantics of indexing were relatively recently changed to do exactly this. This fixes some other issues with assignment. The copy discussion is mostly around the fact that the need for a logic which removes the padding is increased by that behaviour change. And the logic place to do remove it would probably be within copy.
When attempting to create a view of a indexed structured array, in order to create a a standard ndarray, the view method does not appropriately resize the output array. It appears to instead preserve the size of the full structured array.
I have two examples in the code:
As you can see, example #1 is the incorrect size and has garbage from memory in the middle column. Example #2 works as expected.
Reproducing code example:
Numpy/Python version information:
python 3.7.3
numpy 1.16.4
import sys, numpy; print(numpy.version, sys.version)
1.16.4 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0]
The text was updated successfully, but these errors were encountered: