-
-
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
fits.open
does not detect compression in file-like objects
#16171
Comments
Right, it works with a file handle ( astropy/astropy/io/fits/file.py Lines 215 to 220 in d32a06a
(compression guessing happens in _open_fileobj ).Changing isfile is doable but we need to be careful with the impact on other parts of the code.
|
Thanks for the reply! Would changing the |
..answering my own question. It definitely breaks tests if you do that, so something smarter needs to be done in isfile, clearly. |
Maybe |
So I've been trying some things in the hope that they might lead to a PR. I tried adding compression guessing into Which convert the fileobj into a Any attempts to broaden the types detected in |
Description
astropy
fits.open
supports passing a file and a file-like object, and if the file is compressed, this is automatically detected, and handled.However, for file-like objects such as
BytesIO
andSpooledTemporaryFile
, the compression detection does not work, leading to the following error being raised.If the compression detection doesn't work, then the author needs handle this by either adding decompression manually, or maybe write the file to disk then reading it back in.
Reason I hit this error: I'm using FastAPI to fetch a fits file, and it outputs either a
bytes
object or a file-likeSpooledTemporaryFile
which I want to pass tofits.open
.Expected behavior
The following code should work, allowing the gzipped fits file to be read in, and have compression automatically detected.
Note this is just a toy example.
How to Reproduce
This also fails:
Versions
macOS-14.3.1-arm64-arm-64bit
Python 3.11.8 (main, Feb 10 2024, 12:35:50) [Clang 15.0.0 (clang-1500.1.0.2.5)]
astropy 6.0.0
Numpy 1.26.2
pyerfa 2.0.1.1
Scipy 1.12.0
Matplotlib 3.8.3
The text was updated successfully, but these errors were encountered: