Skip to content

Commit 7abc033

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 479ef0c commit 7abc033

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎tests/test_precision.py‎

Lines changed: 13 additions & 4 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())
@@ -389,7 +393,12 @@ def test_time_to_mjd_string_versus_longdouble(format, i_f):
389393
i, f = i_f
390394
m = i + np.longdouble(f)
391395
t = Time(val=i, val2=f, format=format, scale="utc")
392-
assert (abs(np.longdouble(time_to_mjd_string(t)) - m) * u.day).to(u.ns) < 1 * u.ns
396+
tstr = time_to_mjd_string(t)
397+
# NOTE: have to add str() here, because of a numpy bug which treats
398+
# numpy string type differently from python str.
399+
# See https://github.com/numpy/numpy/issues/15608
400+
tld_str = np.longdouble(str(tstr))
401+
assert abs(tld_str - m) * u.day < 1 * u.ns
393402

394403

395404
@given(reasonable_mjd())

0 commit comments

Comments
 (0)