API: Retain arr.base more strictly in np.frombuffer#21632
Merged
charris merged 1 commit intonumpy:mainfrom May 29, 2022
Merged
Conversation
Checking the implementation of `releasebuffer` is the most strict version for when we can safely assume that wrapping into a `memoryview` is not necessary. In theory, `view.obj` could also be set to a new object even with the old buffer-protocol, in practice I don't think that should happen (the docs read like it should not be used). So this is the minimal fix to retain old behavior as much as (safely) possible. Closes numpygh-21612
charris
reviewed
May 29, 2022
| * has to wrap the original object in a Python `memoryview` which deals | ||
| * with the lifetime management for us. | ||
| * For backwards compatibility of `arr.base` we try to avoid this when | ||
| * possible. (For example, NumPy arrays will never get wrapped here!) |
Member
There was a problem hiding this comment.
NumPy arrays will never get wrapped here!
I'll take your word for that. But why not?
Member
Author
There was a problem hiding this comment.
Oh, we don't currently implement releasebuffer. Maybe one day we will, then the test will fail and we should special case them.
Member
|
Thanks Sebastian. |
Contributor
|
Will this patch be included in numpy 1.22.5, >=1.23.0? |
Member
|
It is in 1.23.0. I'm contemplating making 1.22.5 with the patch. A few more complaints might push me to it, as that version will probably be more used over the next year than 1.23. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checking the implementation of
releasebufferis the most strictversion for when we can safely assume that wrapping into a
memoryviewis not necessary.In theory,
view.objcould also be set to a new object even withthe old buffer-protocol, in practice I don't think that should
happen (the docs read like it should not be used).
So this is the minimal fix to retain old behavior as much as
(safely) possible.
Closes gh-21612