Skip to content

Commit 16d229b

Browse files
STY: shorten over-precise float literals to round-trip repr
Following pylint's bad-float-precision (C0330) check, normalize float literals carrying more digits than IEEE 754 binary64 can represent (e.g. ERFA reference fixtures with 17-19 significant digits) to their shortest round-tripping repr — Python's default for repr(float). The parsed float64 value is unchanged on every architecture astropy runs on, so test results are bit-identical.
1 parent ff0dd07 commit 16d229b

24 files changed

Lines changed: 128 additions & 135 deletions

‎astropy/coordinates/tests/test_distance.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_distances():
4242
Distance(unit=u.km)
4343

4444
# standard units are pre-defined
45-
npt.assert_allclose(distance.lyr, 39.138765325702551)
45+
npt.assert_allclose(distance.lyr, 39.13876532570255)
4646
npt.assert_allclose(distance.km, 3.70281309776063e14)
4747

4848
# Coordinate objects can be assigned a distance object, giving them a full
@@ -73,7 +73,7 @@ def test_distances():
7373
# returns a *3d* distance between the c1 and c2 coordinates
7474
# not that this does *not*
7575
assert isinstance(sep12, Distance)
76-
npt.assert_allclose(sep12.pc, 12005.784163916317, 10)
76+
npt.assert_allclose(sep12.pc, 12005.784163916316, 10)
7777

7878
"""
7979
All spherical coordinate systems with distances can be converted to

‎astropy/coordinates/tests/test_earth.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,21 @@ def test_gc2gd():
4747
location = EarthLocation.from_geocentric(x, y, z, u.m)
4848
e, p, h = location.to_geodetic("WGS84")
4949
e, p, h = e.to(u.radian), p.to(u.radian), h.to(u.m)
50-
vvd(e, 0.98279372324732907, 1e-14, "eraGc2gd", "e2", status)
51-
vvd(p, 0.97160184820607853, 1e-14, "eraGc2gd", "p2", status)
52-
vvd(h, 331.41731754844348, 1e-8, "eraGc2gd", "h2", status)
50+
vvd(e, 0.982793723247329, 1e-14, "eraGc2gd", "e2", status)
51+
vvd(p, 0.9716018482060785, 1e-14, "eraGc2gd", "p2", status)
52+
vvd(h, 331.41731754844346, 1e-8, "eraGc2gd", "h2", status)
5353

5454
e, p, h = location.to_geodetic("GRS80")
5555
e, p, h = e.to(u.radian), p.to(u.radian), h.to(u.m)
56-
vvd(e, 0.98279372324732907, 1e-14, "eraGc2gd", "e2", status)
57-
vvd(p, 0.97160184820607853, 1e-14, "eraGc2gd", "p2", status)
58-
vvd(h, 331.41731754844348, 1e-8, "eraGc2gd", "h2", status)
56+
vvd(e, 0.982793723247329, 1e-14, "eraGc2gd", "e2", status)
57+
vvd(p, 0.9716018482060785, 1e-14, "eraGc2gd", "p2", status)
58+
vvd(h, 331.41731754844346, 1e-8, "eraGc2gd", "h2", status)
5959

6060
e, p, h = location.to_geodetic("WGS72")
6161
e, p, h = e.to(u.radian), p.to(u.radian), h.to(u.m)
62-
vvd(e, 0.98279372324732907, 1e-14, "eraGc2gd", "e3", status)
63-
vvd(p, 0.97160181811015119, 1e-14, "eraGc2gd", "p3", status)
64-
vvd(h, 333.27707261303181, 1e-8, "eraGc2gd", "h3", status)
62+
vvd(e, 0.982793723247329, 1e-14, "eraGc2gd", "e3", status)
63+
vvd(p, 0.9716018181101512, 1e-14, "eraGc2gd", "p3", status)
64+
vvd(h, 333.2770726130318, 1e-8, "eraGc2gd", "h3", status)
6565

6666

6767
def test_gd2gc():

‎astropy/coordinates/tests/test_geodetic_representations.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,21 @@ def test_geocentric_to_geodetic(self):
144144
gc = CartesianRepresentation(x, y, z, u.m)
145145
gd = WGS84GeodeticRepresentation.from_cartesian(gc)
146146
e, p, h = gd.lon.to(u.radian), gd.lat.to(u.radian), gd.height.to(u.m)
147-
vvd(e, 0.9827937232473290680, 1e-14, "eraGc2gd", "e1", status)
148-
vvd(p, 0.97160184819075459, 1e-14, "eraGc2gd", "p1", status)
149-
vvd(h, 331.4172461426059892, 1e-8, "eraGc2gd", "h1", status)
147+
vvd(e, 0.982793723247329, 1e-14, "eraGc2gd", "e1", status)
148+
vvd(p, 0.9716018481907546, 1e-14, "eraGc2gd", "p1", status)
149+
vvd(h, 331.41724614260596, 1e-8, "eraGc2gd", "h1", status)
150150

151151
gd = gd.represent_as(GRS80GeodeticRepresentation)
152152
e, p, h = gd.lon.to(u.radian), gd.lat.to(u.radian), gd.height.to(u.m)
153-
vvd(e, 0.98279372324732907, 1e-14, "eraGc2gd", "e2", status)
154-
vvd(p, 0.97160184820607853, 1e-14, "eraGc2gd", "p2", status)
155-
vvd(h, 331.41731754844348, 1e-8, "eraGc2gd", "h2", status)
153+
vvd(e, 0.982793723247329, 1e-14, "eraGc2gd", "e2", status)
154+
vvd(p, 0.9716018482060785, 1e-14, "eraGc2gd", "p2", status)
155+
vvd(h, 331.41731754844346, 1e-8, "eraGc2gd", "h2", status)
156156

157157
gd = gd.represent_as(WGS72GeodeticRepresentation)
158158
e, p, h = gd.lon.to(u.radian), gd.lat.to(u.radian), gd.height.to(u.m)
159-
vvd(e, 0.98279372324732907, 1e-14, "eraGc2gd", "e3", status)
160-
vvd(p, 0.97160181811015119, 1e-14, "eraGc2gd", "p3", status)
161-
vvd(h, 333.27707261303181, 1e-8, "eraGc2gd", "h3", status)
159+
vvd(e, 0.982793723247329, 1e-14, "eraGc2gd", "e3", status)
160+
vvd(p, 0.9716018181101512, 1e-14, "eraGc2gd", "p3", status)
161+
vvd(h, 333.2770726130318, 1e-8, "eraGc2gd", "h3", status)
162162

163163
def test_geodetic_to_geocentric(self):
164164
"""Test that we reproduce erfa/src/t_erfa_c.c t_gd2gc"""

‎astropy/cosmology/_src/tests/flrw/test_lambdacdm.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def test_angular_diameter_distance_z1z2():
501501
# http://www.astro.multivax.de:8000/phillip/angsiz_prog/README.HTML
502502
# Kayser, Helbig, and Schramm (Astron.Astrophys. 318 (1997) 680-686)
503503
assert u.allclose(
504-
tcos.angular_diameter_distance_z1z2(1, 2), 646.22968662822018 * u.Mpc
504+
tcos.angular_diameter_distance_z1z2(1, 2), 646.2296866282202 * u.Mpc
505505
)
506506

507507
z1 = 2 # Separate test for z2<z1, returns negative value with warning
@@ -639,11 +639,11 @@ def test_xtfuncs():
639639
"""Test of absorption and lookback integrand"""
640640
cosmo = LambdaCDM(70, 0.3, 0.5, Tcmb0=2.725)
641641
z = np.array([2.0, 3.2])
642-
assert u.allclose(cosmo.lookback_time_integrand(3), 0.052218976654969378, rtol=1e-4)
642+
assert u.allclose(cosmo.lookback_time_integrand(3), 0.05221897665496938, rtol=1e-4)
643643
assert u.allclose(
644644
cosmo.lookback_time_integrand(z), [0.10333179, 0.04644541], rtol=1e-4
645645
)
646-
assert u.allclose(cosmo.abs_distance_integrand(3), 3.3420145059180402, rtol=1e-4)
646+
assert u.allclose(cosmo.abs_distance_integrand(3), 3.34201450591804, rtol=1e-4)
647647
assert u.allclose(
648648
cosmo.abs_distance_integrand(z), [2.7899584, 3.44104758], rtol=1e-4
649649
)

‎astropy/io/ascii/tests/test_c_reader.py‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ def test_data_out_of_range(fast_reader, guess):
11901190
w[i].message
11911191
)
11921192
read_values = np.array([col[0] for col in t.itercols()])
1193-
assert_allclose(read_values, values, rtol=rtol, atol=1.0e-324)
1193+
assert_allclose(read_values, values, rtol=rtol, atol=0.0)
11941194

11951195
# Test some additional corner cases
11961196
fields = [
@@ -1202,9 +1202,7 @@ def test_data_out_of_range(fast_reader, guess):
12021202
"5200e-327",
12031203
" 0.0000000000000000000001024E+330",
12041204
]
1205-
values = np.array(
1206-
[1.01e200, 3.14e307, 1.777e308, -np.inf, 0.0, 4.94e-324, 1.024e308]
1207-
)
1205+
values = np.array([1.01e200, 3.14e307, 1.777e308, -np.inf, 0.0, 5e-324, 1.024e308])
12081206
with ctx as w:
12091207
t = ascii.read(
12101208
StringIO(" ".join(fields)),
@@ -1222,7 +1220,7 @@ def test_data_out_of_range(fast_reader, guess):
12221220
w[i].message
12231221
)
12241222
read_values = np.array([col[0] for col in t.itercols()])
1225-
assert_allclose(read_values, values, rtol=rtol, atol=1.0e-324)
1223+
assert_allclose(read_values, values, rtol=rtol, atol=0.0)
12261224

12271225
# Test corner cases again with non-standard exponent_style (auto-detection)
12281226
if fast_reader and fast_reader.get("use_fast_converter"):
@@ -1254,7 +1252,7 @@ def test_data_out_of_range(fast_reader, guess):
12541252
else:
12551253
assert len(w) == 3
12561254
read_values = np.array([col[0] for col in t.itercols()])
1257-
assert_allclose(read_values, values, rtol=rtol, atol=1.0e-324)
1255+
assert_allclose(read_values, values, rtol=rtol, atol=0.0)
12581256

12591257

12601258
@pytest.mark.parametrize("guess", [True, False])
@@ -1298,15 +1296,15 @@ def test_data_at_range_limit(fast_reader, guess):
12981296
guess=guess,
12991297
fast_reader=fast_reader,
13001298
)
1301-
assert_allclose(t["col1"][0], 10.0 ** -(D + 1), rtol=rtol, atol=1.0e-324)
1299+
assert_allclose(t["col1"][0], 10.0 ** -(D + 1), rtol=rtol, atol=0.0)
13021300
for D in 99, 202, 308:
13031301
t = ascii.read(
13041302
StringIO("1" + D * "0" + ".0"),
13051303
format="no_header",
13061304
guess=guess,
13071305
fast_reader=fast_reader,
13081306
)
1309-
assert_allclose(t["col1"][0], 10.0**D, rtol=rtol, atol=1.0e-324)
1307+
assert_allclose(t["col1"][0], 10.0**D, rtol=rtol, atol=0.0)
13101308

13111309
# 0.0 is always exact (no Overflow warning)!
13121310
for s in "0.0", "0.0e+0", 399 * "0" + "." + 365 * "0":
@@ -1333,7 +1331,7 @@ def test_data_at_range_limit(fast_reader, guess):
13331331
"resulting in degraded precision" in str(w[0].message)
13341332
)
13351333

1336-
assert_allclose(t["col1"][0], 1.0e-315, rtol=1.0e-10, atol=1.0e-324)
1334+
assert_allclose(t["col1"][0], 1.0e-315, rtol=1.0e-10, atol=0.0)
13371335

13381336

13391337
@pytest.mark.parametrize("guess", [True, False])

‎astropy/io/fits/tests/test_header.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def test_floating_point_string_representation_card(self):
162162
def test_complex_value_card(self):
163163
"""Test Card constructor with complex value"""
164164

165-
c = fits.Card("abc", (1.2345377437887837487e88 + 6324767364763746367e-33j))
165+
c = fits.Card("abc", (1.2345377437887837e88 + 6324767364763746367e-33j))
166166
f1 = _pad("ABC = (1.23453774378878E+88, 6.32476736476374E-15)")
167167
f2 = _pad("ABC = (1.2345377437887E+088, 6.3247673647637E-015)")
168168
f3 = _pad("ABC = (1.23453774378878E+88, 6.32476736476374E-15)")

‎astropy/io/fits/tests/test_table.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_open(self, home_is_data):
200200
x2 = fits.ColDefs(tt[1])
201201
t2 = fits.BinTableHDU.from_columns(x2, nrows=2)
202202
ra = np.rec.array(
203-
[(1, "abc", 3.7000002861022949, 0), (2, "xy ", 6.6999998092651367, 1)],
203+
[(1, "abc", 3.700000286102295, 0), (2, "xy ", 6.699999809265137, 1)],
204204
names="c1, c2, c3, c4",
205205
)
206206

@@ -269,7 +269,7 @@ def test_binary_table(self):
269269
assert t[1].columns.info(output=False) == info
270270

271271
ra = np.rec.array(
272-
[(1, "abc", 3.7000002861022949, 0), (2, "xy ", 6.6999998092651367, 1)],
272+
[(1, "abc", 3.700000286102295, 0), (2, "xy ", 6.699999809265137, 1)],
273273
names="c1, c2, c3, c4",
274274
)
275275

@@ -293,7 +293,7 @@ def test_ascii_table(self):
293293
ra1 = np.rec.array(
294294
[
295295
(10.123000144958496, 37),
296-
(5.1999998092651367, 23),
296+
(5.199999809265137, 23),
297297
(15.609999656677246, 17),
298298
(0.0, 0),
299299
(345.0, 345),

‎astropy/modeling/tests/test_functional_models.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_Gaussian2D_theta():
169169

170170
@pytest.mark.parametrize("gamma", (10, -10))
171171
def test_moffat_fwhm(gamma):
172-
ans = 34.641016151377542
172+
ans = 34.64101615137754
173173
kwargs = {"gamma": gamma, "alpha": 0.5}
174174
m1 = models.Moffat1D(**kwargs)
175175
m2 = models.Moffat2D(**kwargs)

‎astropy/modeling/tests/test_input.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def test_linear_fitter_1dcheb(self):
109109
[
110110
[
111111
2817.2499999999995,
112-
4226.6249999999991,
113-
1680.7500000000009,
112+
4226.624999999999,
113+
1680.750000000001,
114114
273.37499999999926,
115115
]
116116
]

‎astropy/modeling/tests/test_parameters.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def test_par_against_iraf(self):
357357
952.8943813407858,
358358
12.641236013982386,
359359
-1.7910672553339604,
360-
0.90252884366711317,
360+
0.9025288436671132,
361361
]
362362
),
363363
rtol=10 ** (-2),

0 commit comments

Comments
 (0)