From 39a9cfbca2b9990b3477b9092ba2af7bb92aec6c Mon Sep 17 00:00:00 2001 From: Jaime Ruiz-Zapatero Date: Fri, 6 Nov 2026 14:25:15 +0000 Subject: [PATCH] Compare feature values with a tolerance in test_data The coverage channel is a matrix product, so its ones and zeros are only exact to round-off, which depends on the machine (0.9999999999999998 on a CI runner). Co-Authored-By: Claude Opus 5.5 --- tests/test_data.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_data.py b/tests/test_data.py index 5477db2..53f9ce3 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -137,9 +137,10 @@ def test_coverage_is_one_in_observed_filter_bins_and_zero_elsewhere(box_catalog, def test_non_detection_empties_its_bin(box_catalog, box_bands): """Object 2 has no g: bin 3 is zero in both the SED and the coverage, the other bands are unaffected.""" X, _ = catalog_to_XY(box_catalog, box_bands, "i", CONFIG) - assert X[2, BAND_BIN["g"], 0] == 0 and X[2, BAND_BIN["g"], 2] == 0 + assert X[2, BAND_BIN["g"], 0] == pytest.approx(0, abs=1e-12) + assert X[2, BAND_BIN["g"], 2] == pytest.approx(0, abs=1e-12) for b in ("u", "r", "i"): - assert X[2, BAND_BIN[b], 2] == 1 + assert X[2, BAND_BIN[b], 2] == pytest.approx(1, abs=1e-12) def test_wavelength_label_channel(box_catalog, box_bands): @@ -149,7 +150,8 @@ def test_wavelength_label_channel(box_catalog, box_bands): def test_band_missing_from_catalog_is_unobserved(box_catalog, box_bands): X, _ = catalog_to_XY(box_catalog.drop(columns="mag_u"), box_bands, "i", CONFIG) - assert np.all(X[:, BAND_BIN["u"], 0] == 0) and np.all(X[:, BAND_BIN["u"], 2] == 0) + np.testing.assert_allclose(X[:, BAND_BIN["u"], 0], 0, atol=1e-12) + np.testing.assert_allclose(X[:, BAND_BIN["u"], 2], 0, atol=1e-12) def test_wide_filter_fills_all_its_bins(tmp_path):