Closed asmeurer closed 6 months ago
Maybe it had to do with when obj
is not an array. Are there instances where copy=False could fail with the buffer protocol?
Maybe it had to do with when
obj
is not an array. Are there instances where copy=False could fail with the buffer protocol?
No, neither the buffer protocol nor __array_interface__
have that.
Searched through the discussion at https://github.com/numpy/numpy/pull/18585 and couldn't find anything. I think I just wasn't really clear at the time that numpy copy=False worked like copy=None.
OK, I updated this to handle Python built-ins and buffer protocol objects properly, and added some more tests since I don't think the test suite really checks copy
that sufficiently.
For NumPy 2.0, this is implemented directly. For NumPy 1, we emulate it by checking if asarray() creates a copy or not.
This also removes support for the np._CopyMode enum in asarray(), as this is not portable.
@rgommers I can't remember if there was a good reason that we didn't just emulate copy=False in this way originally (instead, we raised
NotImplementedError
).