Skip to content

Create Header instance when _BasicHeader fails#9711

Merged
mhvk merged 6 commits intoastropy:masterfrom
saimn:fits-fix-grouphdu
Dec 18, 2019
Merged

Create Header instance when _BasicHeader fails#9711
mhvk merged 6 commits intoastropy:masterfrom
saimn:fits-fix-grouphdu

Conversation

@saimn
Copy link
Contributor

@saimn saimn commented Dec 3, 2019

Fix #9709 : _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 (#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 (#9709). So in this case we fall back to creating a normal Header instance. I wanted to avoid this because of the performance penalty but here it is limited to specific cases (e.g. invalid headers). And it was useful to not have this from the start, since it was a good mean to find edge cases like this one :)

@MSeifert04
Copy link
Contributor

MSeifert04 commented Dec 3, 2019

The failure TypeError: buffer is too small for requested array from CI looks real, See https://travis-ci.org/astropy/astropy/jobs/619922592#L2310

@saimn saimn force-pushed the fits-fix-grouphdu branch from 8d49163 to 728a952 Compare December 13, 2019 02:47
@saimn
Copy link
Contributor Author

saimn commented Dec 13, 2019

The issue is that fitsdiff has a test that compares all files in the data directory, which fails because here I'm adding an invalid file:
I tried to move the file in a sub-directory, but this is still failing when comparing the data directory to itself, because sub-directories are not filtered in this case:

with pytest.warns(UserWarning, match=r"Field 'ORBPARM' has a repeat "
r"count of 0 in its format code"):
assert fitsdiff.main(["-q", self.data_dir, self.data_dir]) == 0

So I fixed this issue in fitsdiff, even if I'm not too happy with putting another fix in this PR, I don't know how to proceed otherwise.

@saimn
Copy link
Contributor Author

saimn commented Dec 15, 2019

Failure is unrelated (astropy.utils.data.CacheDamaged: Apparently abandoned files).

@pllim
Copy link
Member

pllim commented Dec 15, 2019

Re: CacheDamaged -- FWIW a rebase would get rid of it, as we have temporarily skipped the test.

_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.
@saimn
Copy link
Contributor Author

saimn commented Dec 18, 2019

One unrelated failure in the 32 build, after rebasing :
https://circleci.com/gh/astropy/astropy/56597

______________________ [doctest] docs/io/ascii/index.rst _______________________
[gw3] linux -- Python 3.7.5 /opt/python/cp37-cp37m/bin/python
148   Writing Data Tables as Formatted ASCII Tables
149 
150 The following writes a table as a simple space-delimited file::
151 
152   >>> import numpy as np
153   >>> from astropy.table import Table, Column, MaskedColumn
154   >>> x = np.array([1, 2, 3])
155   >>> y = x ** 2
156   >>> data = Table([x, y], names=['x', 'y'])
157   >>> ascii.write(data, 'values.dat')
UNEXPECTED EXCEPTION: AstropyDeprecationWarning("values.dat already exists. Automatically overwriting ASCII files is deprecated. Use the argument 'overwrite=True' in the future.")
Traceback (most recent call last):

  File "/opt/python/cp37-cp37m/lib/python3.7/doctest.py", line 1329, in __run
    compileflags, 1), test.globs)

  File "<doctest index.rst[13]>", line 1, in <module>

  File "/tmp/astropy-test-ur8e8wgu/lib/python3.7/site-packages/astropy/io/ascii/ui.py", line 750, in write
    output), AstropyDeprecationWarning)

astropy.utils.exceptions.AstropyDeprecationWarning: values.dat already exists. Automatically overwriting ASCII files is deprecated. Use the argument 'overwrite=True' in the future.

@saimn saimn force-pushed the fits-fix-grouphdu branch from 4318fb5 to d7ff06b Compare December 18, 2019 02:43
@saimn
Copy link
Contributor Author

saimn commented Dec 18, 2019

I think it happens because this is the parallelized build, and docs/io/ascii/write.rst also writes a file with the same name (but with overwrite=True). And since tests are run in parallel I guess that write.rst was run before index.rst.

@saimn
Copy link
Contributor Author

saimn commented Dec 18, 2019

So I fixed the changelog, it should be good now. @MSeifert04 seems busy, so maybe @astrofrog or @mhvk you can give it an eye ? 🙏

@saimn saimn requested review from astrofrog and mhvk December 18, 2019 02:54
Copy link
Contributor

@MSeifert04 MSeifert04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a work-around, this is fine, but can you add a comment in base.py why this is done? After all, it is a rather ugly hack and really something that hdu should not have to know about (but then, it also shouldn't be modifying a header!). A comment might just trigger someone willing to really think through how to separate the parts a bit better...

p.s. I just had quite a long look at all these files in order to implement PSRFITS in our package, and was already very confused about this data=DELAYED part, and was rather thankful for the liberally sprinkled comments through the files!

@saimn
Copy link
Contributor Author

saimn commented Dec 18, 2019

@mhvk - Yes you are right, I will add a comment!

@saimn
Copy link
Contributor Author

saimn commented Dec 18, 2019

@mhvk - Done, please have a look. I skipped the CI since this is just a comment change.

@mhvk
Copy link
Contributor

mhvk commented Dec 18, 2019

Thanks, I think that is really helpful and clear. Merging...

@mhvk mhvk merged commit 2f45fae into astropy:master Dec 18, 2019
@MSeifert04
Copy link
Contributor

Thanks @saimn and @mhvk

@saimn saimn deleted the fits-fix-grouphdu branch December 21, 2019 03:51
bsipocz pushed a commit that referenced this pull request Jan 22, 2020
Create Header instance when _BasicHeader fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

astropy.io.fits cannot open any FITS-IDI file

4 participants