'Tests the multidimensional column implementation with both numeric
arrays and string arrays.'

def test_multi_dimensional_columns(self):

    data = np.rec.array([([0, 1, 2, 3, 4, 5], ('row1' * 2)), ([6, 7, 8, 9, 0, 1], ('row2' * 2)), ([2, 3, 4, 5, 6, 7], ('row3' * 2))], formats='6i4,a8')
    thdu = fits.BinTableHDU.from_columns(data)
    thdu.header['TDIM1'] = '(2,3)'
    thdu.header['TDIM2'] = '(4,2)'
    thdu.writeto(self.temp('newtable.fits'))
    with fits.open(self.temp('newtable.fits')) as hdul:
        thdu = hdul[1]
        c1 = thdu.data.field(0)
        c2 = thdu.data.field(1)
        assert (c1.shape == (3, 3, 2))
        assert (c2.shape == (3, 2))
        assert (c1 == np.array([[[0, 1], [2, 3], [4, 5]], [[6, 7], [8, 9], [0, 1]], [[2, 3], [4, 5], [6, 7]]])).all()
        assert (c2 == np.array([['row1', 'row1'], ['row2', 'row2'], ['row3', 'row3']])).all()
    del c1
    del c2
    del thdu
    del hdul
    data = np.zeros(3, dtype=[('x', 'f4'), ('s', 'S5', 4)])
    data['x'] = (1, 2, 3)
    data['s'] = 'ok'
    with ignore_warnings():
        fits.writeto(self.temp('newtable.fits'), data, overwrite=True)
    t = fits.getdata(self.temp('newtable.fits'))
    assert (t.field(1).dtype.str[(-1)] == '5')
    assert (t.field(1).shape == (3, 4))
    data = np.zeros(3, dtype=[('x', 'f4'), ('s', 'S5', (4, 3))])
    data['x'] = (1, 2, 3)
    data['s'] = 'ok'
    del t
    with ignore_warnings():
        fits.writeto(self.temp('newtable.fits'), data, overwrite=True)
    t = fits.getdata(self.temp('newtable.fits'))
    assert (t.field(1).dtype.str[(-1)] == '5')
    assert (t.field(1).shape == (3, 4, 3))
