-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
append mode doesn't work for gzipped files #7457
Comments
Is it possible for you to provide a minimal snippet to reproduce your problem? If you can provide the data (or subset of it), that would be great too. Thanks. |
I seem to remember that there was a good technical reason that |
@pllim sure- This is one dataset I couldn't get it to work on, LBUI23V3Q:
The output should be one PrimaryHDU followed by 3 ImageHDUs, but you can see that when you open the file in append mode, it doesn't end up this way.
This is not necessarily how I would choose to write an output file, but it is currently done this way in calcos |
Does it work before Astropy 3.0 ? (Could it be related to #6373 @drdavella ?) |
I tried with astropy 2.0.6 and 3.0.2 and both produce the same results. |
@saimn yes it could be. I'll take another look. |
@saimn I'm not exactly sure where this bug was introduced, but I wonder if you would be willing to accept as a solution an error when using
Neither |
I'm having a look, and the bug is probably not so difficult to fix. The issue is that for files opened in append mode, the length is 0:
And this is because the gzip file is opened in write-only mode, so reading from it is not possible, and hence the length (number of HDUs) cannot be computed (which causes all HDUs to be added as PrimaryHDU):
Not sure of the best way to fix, opening in 'rb+' mode as for 'update' seems reasonable, @drdavella ? |
@saimn I tried changing it to |
@drdavella - It works for me with |
@drdavella - Ok I think I found the same issue as you ;). I did not get far enough previously, with |
Hmm, but 'update' uses also |
So, it seems that 'update' write to a temporary (writable) file before replacing the original one ( |
Astropy documentation seems to imply that the only type of zipped files that do not work with append or update modes are bzipped files:
http://docs.astropy.org/en/stable/io/fits/#working-with-compressed-files
However, opening in append mode does not work for gzipped files. Update mode does still work.
I'm using python 3.5.5 and astropy 3.0.2
The text was updated successfully, but these errors were encountered: