diff --git a/astropy/io/fits/hdu/hdulist.py b/astropy/io/fits/hdu/hdulist.py index 2d778a28f56a..808cf3e1da01 100644 --- a/astropy/io/fits/hdu/hdulist.py +++ b/astropy/io/fits/hdu/hdulist.py @@ -1,6 +1,5 @@ # Licensed under a 3-clause BSD style license - see PYFITS.rst - import gzip import itertools import os @@ -354,7 +353,7 @@ def __setitem__(self, key, hdu): self._try_while_unread_hdus(super().__setitem__, _key, hdu) except IndexError: raise IndexError('Extension {} is out of bound or not found.' - .format(key)) + .format(key)) self._resize = True self._truncate = False @@ -803,7 +802,7 @@ def flush(self, output_verify='fix', verbose=False): if self._file.mode not in ('append', 'update', 'ostream'): warnings.warn("Flush for '{}' mode is not supported." - .format(self._file.mode), AstropyUserWarning) + .format(self._file.mode), AstropyUserWarning) return save_backup = self._open_kwargs.get('save_backup', False) @@ -1354,7 +1353,10 @@ def _flush_resize(self): # flushing (on Windows--again, this is no problem on Linux). for idx, mmap, arr in mmaps: if mmap is not None: - arr.data = self[idx].data.data + # https://github.com/numpy/numpy/issues/8628 + with warnings.catch_warnings(): + warnings.simplefilter('ignore', category=DeprecationWarning) + arr.data = self[idx].data.data del mmaps # Just to be sure else: diff --git a/astropy/io/fits/tests/test_hdulist.py b/astropy/io/fits/tests/test_hdulist.py index 5de58f5f6560..8c8c75d760a7 100644 --- a/astropy/io/fits/tests/test_hdulist.py +++ b/astropy/io/fits/tests/test_hdulist.py @@ -619,11 +619,6 @@ def test_update_with_truncated_header(self): with fits.open(self.temp('temp.fits')) as hdul: assert (hdul[0].data == data).all() - # This test used to fail on Windows - if it fails again in future, see - # https://github.com/astropy/astropy/issues/5797 - # The warning appears on Windows but cannot be explicitly caught. - @pytest.mark.filterwarnings("ignore:Assigning the 'data' attribute is an " - "inherently unsafe operation") def test_update_resized_header(self): """ Test saving updates to a file where the header is one block smaller diff --git a/astropy/io/fits/tests/test_image.py b/astropy/io/fits/tests/test_image.py index 0273efbeba03..5bbf7759e715 100644 --- a/astropy/io/fits/tests/test_image.py +++ b/astropy/io/fits/tests/test_image.py @@ -239,11 +239,6 @@ def test_primary_with_extname(self): with fits.open(self.temp('test.fits')) as hdul: assert hdul[0].name == 'XPRIMARY2' - # This test used to fail on Windows - if it fails again in future, see - # https://github.com/astropy/astropy/issues/5797 - # The warning appears on Windows but cannot be explicitly caught. - @pytest.mark.filterwarnings("ignore:Assigning the 'data' attribute is an " - "inherently unsafe operation") def test_io_manipulation(self): # Get a keyword value. An extension can be referred by name or by # number. Both extension and keyword names are case insensitive.