Skip to content

Commit 3b60739

Browse files
committed
Work around np.longdouble bug.
Unfortunately, it seems np.longdouble(string) looses precision if string is a numpy string scalar or array rather than a python string. This adjusts the test to not avoid that bug, but does not actually check whether the bug introduces problems elsewhere in the code. See numpy/numpy#15608
1 parent f34bb91 commit 3b60739

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎tests/test_precision.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,13 @@ def test_time_from_longdouble_utc(format, i_f):
363363
def test_time_to_longdouble_close_to_time_to_mjd_string(format, i_f):
364364
i, f = i_f
365365
t = Time(val=i, val2=f, format=format, scale="utc")
366-
assert (
367-
abs(np.longdouble(time_to_mjd_string(t)) - time_to_longdouble(t)) * u.day
368-
).to(u.ns) < 1 * u.ns
366+
tld = time_to_longdouble(t)
367+
tstr = time_to_mjd_string(t)
368+
# NOTE: have to add str() here, because of a numpy bug which treats
369+
# numpy string type differently from python str.
370+
# See https://github.com/numpy/numpy/issues/15608
371+
tld_str = np.longdouble(str(tstr))
372+
assert abs(tld_str - tld) * u.day < 1 * u.ns
369373

370374

371375
@given(reasonable_mjd())

0 commit comments

Comments
 (0)