Skip to content

Commit 313db54

Browse files
committed
Update header when creating GroupsHDU from data (fix astropy#9193)
1 parent b2d59ee commit 313db54

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎astropy/io/fits/hdu/groups.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import numpy as np
55

6-
from .base import DTYPE2BITPIX
6+
from .base import DTYPE2BITPIX, DELAYED
77
from .image import PrimaryHDU
88
from .table import _TableLikeHDU
99
from astropy.io.fits.column import Column, ColDefs, FITS2NUMPY
@@ -268,6 +268,8 @@ class GroupsHDU(PrimaryHDU, _TableLikeHDU):
268268

269269
def __init__(self, data=None, header=None):
270270
super().__init__(data=data, header=header)
271+
if data is not DELAYED:
272+
self.update_header()
271273

272274
# Update the axes; GROUPS HDUs should always have at least one axis
273275
if len(self._axes) <= 0:

‎astropy/io/fits/tests/test_groups.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ def test_create_groupdata(self):
152152

153153
# Test putting the data into a GroupsHDU and round-tripping it
154154
ghdu = fits.GroupsHDU(data=x)
155+
assert ghdu.parnames == ['abc', 'xyz']
156+
assert ghdu.header['GCOUNT'] == 10
157+
155158
ghdu.writeto(self.temp('test.fits'))
156159

157160
with fits.open(self.temp('test.fits')) as h:

0 commit comments

Comments
 (0)