Skip to content

Commit e5fd06b

Browse files
committed
Create Header instance when _BasicHeader fails
_BasicHeader does not support assignment, with the assumption that HDU classes should not need to modify the header at instantiation. This has been true until now, with one exception (astropy#9193) that has been fixed by another mean. The problem addressed here is that GroupsHDU needs to modify the header to handle some invalid header (astropy#9709). So in this case we fall back to creating a normal Header instance.
1 parent 09912f5 commit e5fd06b

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,14 @@ def block_iter(nbytes):
460460
if key not in sig.parameters:
461461
del new_kwargs[key]
462462

463-
hdu = cls(data=DELAYED, header=header, **new_kwargs)
463+
try:
464+
hdu = cls(data=DELAYED, header=header, **new_kwargs)
465+
except TypeError:
466+
if isinstance(header, _BasicHeader):
467+
header = Header.fromstring(header_str)
468+
hdu = cls(data=DELAYED, header=header, **new_kwargs)
469+
else:
470+
raise
464471

465472
# One of these may be None, depending on whether the data came from a
466473
# file or a string buffer--later this will be further abstracted

0 commit comments

Comments
 (0)