Repository navigation
Description
Description
Working in an HPC environment, we routinely follow the guidelines for using IERS code offline, including setting iers.conf.auto_max_age = None. Previously, in #10126, we fixed some numerical issues with comparing floating point numbers to None. However, that did not fix some overflow warnings which are distracting, to the point where some colleagues thought that actual time calculations were being corrupted (they are not).
Expected behavior
astropy.utils.iers.iers.LeapSeconds.auto_open() should be able to handle iers.conf.auto_max_age = None gracefully.
In other words, if iers.conf.auto_max_age = None, simply pick a value for good_enough (in auto_open(), see below for link) that doesn't generate an overflow warning. I actually contributed #10126, but I can't recall why that was not handled at that time.
Actual behavior
iers.conf.auto_max_age = None is converted into a numerical value, np.finfo(float).max, which is appropriate in other parts of the code, but not the calculation in astropy.utils.iers.iers.LeapSeconds.auto_open().
Steps to Reproduce
The snippet below reproduces the code in astropy.utils.iers.iers.LeapSeconds, in particular, this line:
>>> import astropy
>>> astropy.__version__
'4.3.1'
>>> from astropy.time import Time, TimeDelta
>>> from datetime import datetime
>>> from astropy.utils.iers.iers import _none_to_float
>>> s = '{0.year:04d}-{0.month:02d}-{0.day:02d}'.format(datetime.utcnow())
>>> today = Time(s, scale='tai', format='iso', out_subfmt='date')
>>> TimeDelta(180-_none_to_float(None), format='jd')
/Users/weaver/Documents/local/products/venv/astropy4/lib/python3.8/site-packages/astropy/time/utils.py:179: RuntimeWarning: overflow encountered in double_scalars
c = 134217729. * a # 2**27+1.
/Users/weaver/Documents/local/products/venv/astropy4/lib/python3.8/site-packages/astropy/time/utils.py:181: RuntimeWarning: invalid value encountered in double_scalars
ah = c - abig
<TimeDelta object: scale='None' format='jd' value=nan>
>>> today + TimeDelta(180-_none_to_float(None), format='jd')
/Users/weaver/Documents/local/products/venv/astropy4/lib/python3.8/site-packages/astropy/time/utils.py:179: RuntimeWarning: overflow encountered in double_scalars
c = 134217729. * a # 2**27+1.
/Users/weaver/Documents/local/products/venv/astropy4/lib/python3.8/site-packages/astropy/time/utils.py:181: RuntimeWarning: invalid value encountered in double_scalars
ah = c - abig
/Users/weaver/Documents/local/products/venv/astropy4/lib/python3.8/site-packages/erfa/core.py:16224: RuntimeWarning: invalid value encountered in d2dtf
iy, im, id, ihmsf, c_retval = ufunc.d2dtf(scale, ndp, d1, d2)
<Time object: scale='tai' format='iso' value=-4713-11-24>System Details
Numpy 1.21.4
pyerfa 2.0.0.1
astropy 4.3.1
Scipy 1.7.2
Matplotlib 3.5.0
As far as I can tell the relevant code has not changed from 4.3.1 to 5.0.
Activity
pllim commentedon Jan 10, 2022
Would something like #12713 work for you or even correct approach?
weaverba137 commentedon Jan 10, 2022
Yes, that looks like the right approach, but I might not be able to test it until tomorrow.
pllim commentedon Jan 10, 2022
No rush, though it might miss 5.0.1 anyway, so you'll have to wait till 5.0.2 to get this patch.