Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving large table FITS may lead to a truncated file #4307

Merged
merged 4 commits into from
Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@ Bug Fixes

- ``astropy.io.fits``

- Fixed a regression that could cause writes of large FITS files to be
truncated. [#4307]

- ``astropy.io.misc``

- ``astropy.io.registry``
Expand Down
5 changes: 2 additions & 3 deletions astropy/io/fits/hdu/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from ..file import _File
from ..header import Header, _pad_length
from ..util import (_is_int, _is_pseudo_unsigned, _unsigned_zero,
itersubclasses, decode_ascii,
_get_array_mmap, _array_to_file, first)
itersubclasses, decode_ascii, _get_array_mmap, first)
from ..verify import _Verify, _ErrList

from ....extern.six import string_types, add_metaclass
Expand Down Expand Up @@ -727,7 +726,7 @@ def _writedata_direct_copy(self, fileobj):

raw = self._get_raw_data(self._data_size, 'ubyte', self._data_offset)
if raw is not None:
_array_to_file(raw, fileobj)
fileobj.writearray(raw)
return raw.nbytes
else:
return 0
Expand Down
2 changes: 2 additions & 0 deletions astropy/io/fits/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import division

import errno
import gzip as _system_gzip
import itertools
import io
Expand Down Expand Up @@ -862,6 +863,7 @@ def _write_string(f, s):
elif isinstance(f, StringIO) and isinstance(s, np.ndarray):
# Workaround for StringIO/ndarray incompatibility
s = s.data

f.write(s)


Expand Down