Let view include dtype change and pass that to __array_finalize__ #31271
Let view include dtype change and pass that to __array_finalize__ #31271mhvk wants to merge 4 commits intonumpy:mainfrom
Conversation
|
The intermediate view may not be a big deal, but yeah, it's definitely nice to skip it!
I like this in principle, but I think there are two subtleties, and unless we shrug them off (probably OK, but...), I am actually not sure there is a clean solution:
Now, I can see calling
So, in my approach With But too much text, not sure what it gives us. To me using |
This is an alternative to #31234, which aims to have
PyArray_View()do a one-step view of both a possibly new subtype and a new dtype. In principle, I feel that is where we should be aiming, but I found that forMaskedArrayI had to make more changes than in #31324, because its__array_finalize__relies on the dtype not being correct yet.Given that, there may be other code that relies on the current behaviour of view, so if we go with this at all, I would need to add code similar to #31324 to check whether someone has a dtype override (I think
_set_dtypeis not present in any published version, so one would perhaps not have to check for that).Also, when thinking about this more, I realize that in this PR, the shape and strides can be incorrect when
__array_finalize__is called. This is not difficult to solve, but I thought I would get some opinions on whether this is the right direction at all before doing that. Though opening as draft for nowNote that now that I've made this, I think there is very little reason not just to put in #31234, as it seems clear that what I have here can be done as follow up as well.
No AI was used.