Fix use of frombuffer which made array read-only - #6923
Conversation
Fix astropy#6862. astropy#6785 replaced uses of np.fromstring with np.frombuffer but the latter returns a read-only view of the binary buffer. So copying the array is needed to get a writeable array (and np.fromstring was doing the copy internally).
|
Hi there @saimn 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃. Everything looks good from my point of view! 👍 If there are any issues with this message, please report them here. |
|
LGTM, assuming the tests pass. |
|
@astrofrog - Yes, with the price of a copy. But it's only worse if compared to master, otherwise |
|
@saimn - that's true - in any case I agree that for now this is fine as it doesn't make the performance worse compared to the last release. |
|
Ok, merging now then. |
|
Thanks @saimn |
Fix use of frombuffer which made array read-only
Fix use of frombuffer which made array read-only
Fix #6862.
#6785 replaced
np.fromstringwithnp.frombufferbut the latter returns a read-only view of the binary buffer. So copying the array is needed to get a writeable array.From what I can understand from the numpy code,
np.fromstringwas doing the copy internally. This seems true also when doing a quick test to compare the two functions,np.frombufferdoes not allocate memory.