Skip to content

Fix io.fits failure on 32-bit systems - #5078

Merged
astrofrog merged 3 commits into
astropy:masterfrom
astrofrog:fix-32bit-buffer-error
Sep 2, 2016
Merged

astrofrog merged 3 commits into
astropy:masterfrom
astrofrog:fix-32bit-buffer-error

Conversation

@astrofrog

Copy link
Copy Markdown
Member

This fixes the TypeError: 'buffer' does not have the buffer interface test failures that occurred in io.fits on 32-bit Linux systems (see #3380).

@embray - could you review this?

@astrofrog

Copy link
Copy Markdown
Member Author

I'm marking this as 'no changelog entry needed' for now because I'm not aware of any real-life cases where this caused issues. However, I could always add one if needed.

@astrofrog astrofrog modified the milestones: v1.2.1, v1.2.2 Jun 24, 2016
@astrofrog

Copy link
Copy Markdown
Member Author

@eteq - does this looks reasonable? (this PR has been open for a while, but no feedback, so would like to go ahead and merge, but not comfortable doing that without review)

Comment thread astropy/io/fits/util.py
`numpy.ndarray.tofile`).
"""

if len(arr) == 0:

@MSeifert04 MSeifert04 Aug 10, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

According to PEP8 one generally uses if not len(arr): (or if not arr.size) instead of directly comparing it with == 0.

As a side note: What does this line fix? Could you add a short comment why it is necessary or convenient?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think the code is fine as-is personally, I don't think if not len(arr) is as readable...

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.

I agree with @astrofrog

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.

For scientific code especially I prefer len(...) == 0 because the expectation is more explicit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@MSeifert04 I added a comment - this is just a shortcut to avoid executing the rest of the function.

@astrofrog

Copy link
Copy Markdown
Member Author

I'll go ahead and merge this since @embray 👍 'd this above

@astrofrog
astrofrog merged commit 61f8932 into astropy:master Sep 2, 2016
eteq pushed a commit that referenced this pull request Dec 21, 2016
@astrofrog
astrofrog deleted the fix-32bit-buffer-error branch November 14, 2018 15:24
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