Allow Path in reproject_from_healpix - #625
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #625 +/- ##
=======================================
Coverage 90.62% 90.62%
=======================================
Files 51 51
Lines 2431 2433 +2
=======================================
+ Hits 2203 2205 +2
Misses 228 228 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| if isinstance(input_data, str | Path): | ||
| with fits.open(input_data) as hdulist: | ||
| return parse_input_healpix_data(hdulist[hdu_in or 1], field=field) | ||
| if isinstance(input_data, tuple) and isinstance(input_data[0], np.ndarray): |
There was a problem hiding this comment.
Just curious, why was this changed from elif to if? (and same above)
There was a problem hiding this comment.
This was a tiny bit of refactoring on my part. The previous state was very close to a series of guard clauses, so I formulated it more directly that way. I think the logic remains identical. Following a guard clause style, the early returns mean we don't have to worry about the else portions from each previous check.
There was a problem hiding this comment.
Something that did just catch my attention now is that the final type error isn't really complete, and it doesn't really tell the caller what ended up there. I'd be tempted to make it something like:
msg = (
"input_data should be an HDU object, a filename, or a tuple "
f"of (array, frame), got {type(input_data)=}"
)
raise TypeError(msg)There was a problem hiding this comment.
FWIW - there's even a Ruff rule that enforces this
https://docs.astral.sh/ruff/rules/superfluous-else-return/
Which is maybe why I've picked up the habit!
There was a problem hiding this comment.
Feel free to adjust the error message - your suggestion would be an improvement
The docs of
reproject_from_healpixstate:However, in the current first branch is only checked in 'The name of a HEALPIX FITS file' is a
strtype. This is a simple PR to fix the type checking forinput_data.