BUG: printing Angle, Latitude, Longitude with a NaN in degrees
See original GitHub issueDescription
Though nan degrees is a valid initializer, it cannot be printed
print(coord.Longitude(np.nan * u.deg))
Expected behavior
The same as nan radians, but in degrees.
print(coord.Longitude(np.nan * u.rad))
Actual behavior
degrees, unlike radians, appears to call sexagesimal_to_string which has int(values[1])
, but nan cannot be converted to an integer, so it fails.
~/local/astropy/astropy/coordinates/angle_utilities.py in sexagesimal_to_string(values, precision, pad, sep, fields)
637 literal = ''.join(literal)
638 return literal.format(np.copysign(values[0], sign),
--> 639 int(values[1]), values[2],
640 sep=sep, pad=pad,
641 last_value=last_value)
ValueError: cannot convert float NaN to integer
Steps to Reproduce
import astropy.units as u
import astropy.coordinates as coord
print(coord.Longitude(np.nan * u.deg))
System Details
macOS-10.16-x86_64-i386-64bit Python 3.8.2 | packaged by conda-forge | (default, Apr 24 2020, 07:56:27) [Clang 9.0.1 ] Numpy 1.18.4 astropy 4.3.dev721+g3646d9e6e.d20210403 Scipy 1.4.1 Matplotlib 3.4.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Tracking angles and the "NAN" problem... - Parallax Forums
Upon rotation, the gAng values become useless and the angle of rotation cannot be tracked to even the slightest degree with the gyro...
Read more >Float prints as NaN, but prints correct value immediately ...
For some reason the latitude of the first EQ is nan when it is first printed, but prints correctly the second time. There...
Read more >How is it possible to calculate azimuth from a single lat lon ...
To be more precise, I'm trying to calculate a latitude, longitude for any given pixel location in a map (which is an image)....
Read more >Calculate distance, bearing and more between Latitude ...
Calculate distance, bearing and more between Latitude/Longitude points ... that mixing degrees & radians is often the easiest route to head-scratching bugs.
Read more >Math.atan2() - JavaScript - MDN Web Docs
atan2() function returns the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure. I’ll take this issue then!
To clarify since in #11491 there seems to be confusion, the issue here is not just that
nan
raises an error, but also that the output should make clear that the value is actuallynan
, i.e., it should be something like what happens for QuantityOf course, a mix of valid and nan values should give sensible output as well.