-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
ENH: CADC: fix the ability to pass on Path objects as output_file
#2541
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2541 +/- ##
==========================================
+ Coverage 63.63% 64.01% +0.37%
==========================================
Files 132 132
Lines 17092 16972 -120
==========================================
- Hits 10876 10864 -12
+ Misses 6216 6108 -108
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Unfortunately this (the test itself) doesn't seem to work with astropy<5.1. While the relevant votable.utils.convert_to_writable_filelike function doesn't seem to change for a very long time, I didn't follow the call sequence. Instead will simply just skip the test for older versions (and please do advise if you see a workaround, but I don't think it's worth spending too much time with it)
|
70888e2
to
f22c5af
Compare
@@ -56,6 +56,9 @@ cadc | |||
|
|||
- Deprecated keywords and ``run_query`` method have been removed. [#2389] | |||
|
|||
- Fixed a bug to be able to pass longer that filename Path objects as | |||
``output_file``. [#2541] | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this was a bug. The documentation for the method states that output_file
is either a string or a file handler. Adding support for Path
in addition to that is a great idea but it's a new feature.
astroquery/cadc/core.py
Outdated
if isinstance(output_file, str): | ||
fname = output_file | ||
elif hasattr(output_file, 'name'): | ||
fname = output_file.name | ||
fname = str(output_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second block is meant of file handlers. Maybe all is needed is for the first if to be if isinstance(output_file, (str, Path)): name = str(output_file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I can do that, it makes sense. Though it would also make sense to add a test for the file handler case.
f22c5af
to
3488f3e
Compare
58cbe07
to
ff63930
Compare
ff63930
to
2b67e7b
Compare
2b67e7b
to
0436007
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent! Thanks for the contribution!
I'm not sure what goes on with the open file/etc issues on windows, maybe @pllim has a suggestion how to patch that failure around? |
I feel like we seen this in |
I don't run open files check, this just chokes on the warning itself. I'm just leaning towards catching and ignoring it for windows. |
Might be the same problem as astropy/astropy#7404 ? |
off topic but that is a very sad issue, full of the most amazing people most of whom already left. |
97999a4
to
5ce572b
Compare
output_file
output_file
OK, so windows is worked around. Given that there were no tests for the other OSes, I still consider that this PR leaves the code in a better shape. If anyone has an idea how to fix windows, PRs are welcome :) |
I am experiencing the issue in astropy/astropy#7404: while trying to combine multiple fits into one file, individual hduls are closed at the point you want to save the new file:
I can make it work by creating new hdus for with the existing hdu.data and hdu.headr (although I would swear the combined files are much larger than expected) I wonder @bsipocz if you could share your work around for windows. Thanks for any advice. |
@Vital-Fernandez - I would consider moving this discussion upstream to astropy as we don't have a solution or workaround for it here. We just simply skipped testing this on windows. |
fixes #2540