question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: printing Angle, Latitude, Longitude with a NaN in degrees

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
JasonS09commented, Jul 12, 2021

Sure. I’ll take this issue then!

1reaction
mhvkcommented, Apr 8, 2021

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 actually nan, i.e., it should be something like what happens for Quantity

In [3]: u.Quantity(np.nan, u.deg)
Out[3]: <Quantity nan deg>

Of course, a mix of valid and nan values should give sensible output as well.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found