'Regression test for https://github.com/astropy/astropy/issues/4452
Ensure that changes to values in a string column are saved when
a file is opened in ``mode=\'update\'``.'

def test_update_string_column_inplace(self):

    data = np.array([('abc',)], dtype=[('a', 'S3')])
    fits.writeto(self.temp('test.fits'), data)
    with fits.open(self.temp('test.fits'), mode='update') as hdul:
        hdul[1].data['a'][0] = 'XYZ'
        assert (hdul[1].data['a'][0] == 'XYZ')
    with fits.open(self.temp('test.fits')) as hdul:
        assert (hdul[1].data['a'][0] == 'XYZ')
    data = np.array([([['abc', 'def', 'geh'], ['ijk', 'lmn', 'opq']],)], dtype=[('a', ('S3', (2, 3)))])
    fits.writeto(self.temp('test2.fits'), data)
    expected = [['abc', 'def', 'geh'], ['ijk', 'XYZ', 'opq']]
    with fits.open(self.temp('test2.fits'), mode='update') as hdul:
        assert (hdul[1].header['TDIM1'] == '(3,3,2)')
        hdul[1].data['a'][(0, 1, 1)] = 'XYZ'
        assert np.all((hdul[1].data['a'][0] == expected))
    with fits.open(self.temp('test2.fits')) as hdul:
        assert (hdul[1].header['TDIM1'] == '(3,3,2)')
        assert np.all((hdul[1].data['a'][0] == expected))
