'Regression test for https://github.com/astropy/astropy/issues/2595'

def test_empty(self):

    hdu = fits.CompImageHDU()
    assert (hdu.data is None)
    hdu.writeto(self.temp('test.fits'))
    with fits.open(self.temp('test.fits'), mode='update') as hdul:
        assert (len(hdul) == 2)
        assert isinstance(hdul[1], fits.CompImageHDU)
        assert (hdul[1].data is None)
        hdul[1].data = np.arange(100, dtype=np.int32)
    with fits.open(self.temp('test.fits')) as hdul:
        assert (len(hdul) == 2)
        assert isinstance(hdul[1], fits.CompImageHDU)
        assert np.all((hdul[1].data == np.arange(100, dtype=np.int32)))
