Skip to content

Fix use of frombuffer which made array read-only - #6923

Merged
saimn merged 1 commit into
astropy:masterfrom
saimn:fix-fits-readonly
Dec 4, 2017
Merged

saimn merged 1 commit into
astropy:masterfrom
saimn:fix-fits-readonly

Conversation

@saimn

@saimn saimn commented Dec 3, 2017

Copy link
Copy Markdown
Contributor

Fix #6862.

#6785 replaced 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.

From what I can understand from the numpy code, np.fromstring was doing the copy internally. This seems true also when doing a quick test to compare the two functions, np.frombuffer does not allocate memory.

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).
@astropy-bot

astropy-bot Bot commented Dec 3, 2017

Copy link
Copy Markdown

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.

@saimn
saimn requested review from MSeifert04 and drdavella December 3, 2017 23:40
@saimn

saimn commented Dec 3, 2017

Copy link
Copy Markdown
Contributor Author

@bsipocz - This should go in 2.0.3 if possible as #6785 was backported.

@MSeifert04

Copy link
Copy Markdown
Contributor

LGTM, assuming the tests pass.

@astrofrog astrofrog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good, but just to check, will this lead to worse performance for people who don't need writeable arrays?

@saimn

saimn commented Dec 4, 2017

Copy link
Copy Markdown
Contributor Author

@astrofrog - Yes, with the price of a copy. But it's only worse if compared to master, otherwise fromstring was already doing the copy. And it's only when reading data from a file descriptor. Maybe we could do something to respect the fits file mode (with the readonly and denywrite options), and avoid the copy in this case ?

@astrofrog

Copy link
Copy Markdown
Member

@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.

@saimn

saimn commented Dec 4, 2017

Copy link
Copy Markdown
Contributor Author

Ok, merging now then.

@saimn
saimn merged commit e05cded into astropy:master Dec 4, 2017
@saimn
saimn deleted the fix-fits-readonly branch December 4, 2017 11:39
@Cadair

Cadair commented Dec 4, 2017

Copy link
Copy Markdown
Member

Thanks @saimn

bsipocz pushed a commit that referenced this pull request Dec 5, 2017
Fix use of frombuffer which made array read-only
bsipocz pushed a commit that referenced this pull request Dec 5, 2017
Fix use of frombuffer which made array read-only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants