From eafcae4ae78e27c43d223bc158face170b82e274 Mon Sep 17 00:00:00 2001 From: viknesh-ai Date: Mon, 10 Aug 2026 18:26:22 +0530 Subject: [PATCH 1/4] Migrate tests/test_aamp.py from npt.assert_almost_equal to npt.assert_allclose npt.assert_almost_equal only checks a fixed absolute tolerance, and NumPy's docs recommend assert_allclose instead. Every comparison in this file is against `ref_mp`/`comp_mp` (or a column slice of it), which combine a float distance column with int index columns and so come back dtype=object - np.isclose can't handle that directly. Cast both sides to float64 before comparing instead of leaving these on the deprecated API; the values are always numeric so the cast is exact. rtol is left at its default rather than pinned to 0. First of a per-file split of #1175, per review feedback. --- tests/test_aamp.py | 118 +++++++++++++++++++++++++++++++++------------ 1 file changed, 86 insertions(+), 32 deletions(-) diff --git a/tests/test_aamp.py b/tests/test_aamp.py index ac83786a9..9a8e4b84a 100644 --- a/tests/test_aamp.py +++ b/tests/test_aamp.py @@ -35,11 +35,15 @@ def test_aamp_self_join(T_A, T_B): comp_mp = aamp(T_B, m, p=p) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) comp_mp = aamp(pd.Series(T_B), m, p=p) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) @pytest.mark.parametrize("T_A, T_B", test_data) @@ -50,11 +54,15 @@ def test_aamp_A_B_join(T_A, T_B): comp_mp = aamp(T_A, m, T_B, ignore_trivial=False, p=p) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False, p=p) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) def test_aamp_constant_subsequence_self_join(): @@ -64,11 +72,15 @@ def test_aamp_constant_subsequence_self_join(): comp_mp = aamp(T_A, m, ignore_trivial=True) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0]) # ignore indices + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0]) # ignore indices + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + ) # ignore indices def test_aamp_one_constant_subsequence_A_B_join(): @@ -79,18 +91,24 @@ def test_aamp_one_constant_subsequence_A_B_join(): comp_mp = aamp(T_A, m, T_B, ignore_trivial=False) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0]) # ignore indices + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0]) # ignore indices + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + ) # ignore indices # Swap inputs ref_mp = naive.aamp(T_B, m, T_B=T_A) comp_mp = aamp(T_B, m, T_A, ignore_trivial=False) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0]) # ignore indices + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + ) # ignore indices def test_aamp_two_constant_subsequences_A_B_join(): @@ -103,22 +121,30 @@ def test_aamp_two_constant_subsequences_A_B_join(): comp_mp = aamp(T_A, m, T_B, ignore_trivial=False) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0]) # ignore indices + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0]) # ignore indices + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + ) # ignore indices # Swap inputs ref_mp = naive.aamp(T_B, m, T_B=T_A) comp_mp = aamp(T_B, m, T_A, ignore_trivial=False) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0]) # ignore indices + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + ) # ignore indices comp_mp = aamp(pd.Series(T_B), m, pd.Series(T_A), ignore_trivial=False) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0]) # ignore indices + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + ) # ignore indices def test_aamp_identical_subsequence_self_join(): @@ -131,14 +157,18 @@ def test_aamp_identical_subsequence_self_join(): comp_mp = aamp(T_A, m, ignore_trivial=True) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal( - ref_mp[:, 0], comp_mp[:, 0], decimal=config.STUMPY_TEST_PRECISION + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), + comp_mp[:, 0].astype(np.float64), + atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True) naive.replace_inf(comp_mp) - npt.assert_almost_equal( - ref_mp[:, 0], comp_mp[:, 0], decimal=config.STUMPY_TEST_PRECISION + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), + comp_mp[:, 0].astype(np.float64), + atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices @@ -153,14 +183,18 @@ def test_aamp_identical_subsequence_A_B_join(): comp_mp = aamp(T_A, m, T_B, ignore_trivial=False) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal( - ref_mp[:, 0], comp_mp[:, 0], config.STUMPY_TEST_PRECISION + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), + comp_mp[:, 0].astype(np.float64), + atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) naive.replace_inf(comp_mp) - npt.assert_almost_equal( - ref_mp[:, 0], comp_mp[:, 0], config.STUMPY_TEST_PRECISION + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), + comp_mp[:, 0].astype(np.float64), + atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices # Swap inputs @@ -168,8 +202,10 @@ def test_aamp_identical_subsequence_A_B_join(): comp_mp = aamp(T_B, m, T_A, ignore_trivial=False) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal( - ref_mp[:, 0], comp_mp[:, 0], config.STUMPY_TEST_PRECISION + npt.assert_allclose( + ref_mp[:, 0].astype(np.float64), + comp_mp[:, 0].astype(np.float64), + atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices @@ -189,11 +225,15 @@ def test_aamp_nan_inf_self_join(T_A, T_B, substitute_B, substitution_locations): comp_mp = aamp(T_B_sub, m, ignore_trivial=True) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) comp_mp = aamp(pd.Series(T_B_sub), m, ignore_trivial=True) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) @pytest.mark.parametrize("T_A, T_B", test_data) @@ -219,13 +259,17 @@ def test_aamp_nan_inf_A_B_join( comp_mp = aamp(T_A_sub, m, T_B_sub, ignore_trivial=False) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) comp_mp = aamp( pd.Series(T_A_sub), m, pd.Series(T_B_sub), ignore_trivial=False ) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) def test_aamp_nan_zero_mean_self_join(): @@ -237,7 +281,9 @@ def test_aamp_nan_zero_mean_self_join(): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) @pytest.mark.parametrize("T_A, T_B", test_data) @@ -249,11 +295,15 @@ def test_aamp_self_join_KNN(T_A, T_B): comp_mp = aamp(T_B, m, p=p, k=k) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) comp_mp = aamp(pd.Series(T_B), m, p=p, k=k) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) @pytest.mark.parametrize("T_A, T_B", test_data) @@ -265,10 +315,14 @@ def test_aamp_A_B_join_KNN(T_A, T_B): comp_mp = aamp(T_A, m, T_B, ignore_trivial=False, p=p, k=k) naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) comp_mp = aamp( pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False, p=p, k=k ) naive.replace_inf(comp_mp) - npt.assert_almost_equal(ref_mp, comp_mp) + npt.assert_allclose( + ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + ) From ae1de57c5f46e158fd260f23a26d1ba88399ad8d Mon Sep 17 00:00:00 2001 From: viknesh-ai Date: Tue, 11 Aug 2026 21:04:32 +0530 Subject: [PATCH 2/4] Addressed comments Flip npt.assert_allclose args so the stumpy-computed value is `actual` (1st) and naive is `desired` (2nd), and use a literal atol (1.5e-05) instead of a computed 1.5 * 10**-config.STUMPY_TEST_PRECISION expression for consistency. Also drops the now-unused config import. --- tests/test_aamp.py | 66 +++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/test_aamp.py b/tests/test_aamp.py index 9a8e4b84a..d9e5b52f5 100644 --- a/tests/test_aamp.py +++ b/tests/test_aamp.py @@ -4,7 +4,7 @@ import pandas as pd import pytest -from stumpy import config, rng +from stumpy import rng from stumpy.aamp import aamp test_data = [ @@ -36,13 +36,13 @@ def test_aamp_self_join(T_A, T_B): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) comp_mp = aamp(pd.Series(T_B), m, p=p) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -55,13 +55,13 @@ def test_aamp_A_B_join(T_A, T_B): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False, p=p) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -73,13 +73,13 @@ def test_aamp_constant_subsequence_self_join(): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices @@ -92,13 +92,13 @@ def test_aamp_one_constant_subsequence_A_B_join(): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices # Swap inputs @@ -107,7 +107,7 @@ def test_aamp_one_constant_subsequence_A_B_join(): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices @@ -122,13 +122,13 @@ def test_aamp_two_constant_subsequences_A_B_join(): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices # Swap inputs @@ -137,13 +137,13 @@ def test_aamp_two_constant_subsequences_A_B_join(): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices comp_mp = aamp(pd.Series(T_B), m, pd.Series(T_A), ignore_trivial=False) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), atol=1.5e-07 + comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices @@ -158,17 +158,17 @@ def test_aamp_identical_subsequence_self_join(): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), - atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, + ref_mp[:, 0].astype(np.float64), + atol=1.5e-05, ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), - atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, + ref_mp[:, 0].astype(np.float64), + atol=1.5e-05, ) # ignore indices @@ -184,17 +184,17 @@ def test_aamp_identical_subsequence_A_B_join(): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), - atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, + ref_mp[:, 0].astype(np.float64), + atol=1.5e-05, ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), - atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, + ref_mp[:, 0].astype(np.float64), + atol=1.5e-05, ) # ignore indices # Swap inputs @@ -203,9 +203,9 @@ def test_aamp_identical_subsequence_A_B_join(): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp[:, 0].astype(np.float64), comp_mp[:, 0].astype(np.float64), - atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, + ref_mp[:, 0].astype(np.float64), + atol=1.5e-05, ) # ignore indices @@ -226,13 +226,13 @@ def test_aamp_nan_inf_self_join(T_A, T_B, substitute_B, substitution_locations): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) comp_mp = aamp(pd.Series(T_B_sub), m, ignore_trivial=True) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -260,7 +260,7 @@ def test_aamp_nan_inf_A_B_join( naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) comp_mp = aamp( @@ -268,7 +268,7 @@ def test_aamp_nan_inf_A_B_join( ) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -282,7 +282,7 @@ def test_aamp_nan_zero_mean_self_join(): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -296,13 +296,13 @@ def test_aamp_self_join_KNN(T_A, T_B): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) comp_mp = aamp(pd.Series(T_B), m, p=p, k=k) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -316,7 +316,7 @@ def test_aamp_A_B_join_KNN(T_A, T_B): naive.replace_inf(ref_mp) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) comp_mp = aamp( @@ -324,5 +324,5 @@ def test_aamp_A_B_join_KNN(T_A, T_B): ) naive.replace_inf(comp_mp) npt.assert_allclose( - ref_mp.astype(np.float64), comp_mp.astype(np.float64), atol=1.5e-07 + comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) From 957902a71be9a01a273c40c926de0478a59cfb86 Mon Sep 17 00:00:00 2001 From: viknesh-ai Date: Wed, 12 Aug 2026 18:10:24 +0530 Subject: [PATCH 3/4] Addressed comments Keep the reference to config.STUMPY_TEST_PRECISION instead of hardcoding its current value as a literal atol. --- tests/test_aamp.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_aamp.py b/tests/test_aamp.py index d9e5b52f5..e62b447fc 100644 --- a/tests/test_aamp.py +++ b/tests/test_aamp.py @@ -4,7 +4,7 @@ import pandas as pd import pytest -from stumpy import rng +from stumpy import config, rng from stumpy.aamp import aamp test_data = [ @@ -160,7 +160,7 @@ def test_aamp_identical_subsequence_self_join(): npt.assert_allclose( comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), - atol=1.5e-05, + atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True) @@ -168,7 +168,7 @@ def test_aamp_identical_subsequence_self_join(): npt.assert_allclose( comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), - atol=1.5e-05, + atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices @@ -186,7 +186,7 @@ def test_aamp_identical_subsequence_A_B_join(): npt.assert_allclose( comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), - atol=1.5e-05, + atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) @@ -194,7 +194,7 @@ def test_aamp_identical_subsequence_A_B_join(): npt.assert_allclose( comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), - atol=1.5e-05, + atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices # Swap inputs @@ -205,7 +205,7 @@ def test_aamp_identical_subsequence_A_B_join(): npt.assert_allclose( comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), - atol=1.5e-05, + atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices From 753eb0c6f7e9c4283238acd184dd113f67f07c45 Mon Sep 17 00:00:00 2001 From: viknesh-ai Date: Thu, 13 Aug 2026 11:55:02 +0530 Subject: [PATCH 4/4] Addressed comments Rename comp_mp to cmp_mp so ref and cmp are both three letters. --- tests/test_aamp.py | 162 ++++++++++++++++++++++----------------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/tests/test_aamp.py b/tests/test_aamp.py index e62b447fc..30762c853 100644 --- a/tests/test_aamp.py +++ b/tests/test_aamp.py @@ -32,17 +32,17 @@ def test_aamp_self_join(T_A, T_B): m = 3 for p in [1.0, 2.0, 3.0]: ref_mp = naive.aamp(T_B, m, p=p) - comp_mp = aamp(T_B, m, p=p) + cmp_mp = aamp(T_B, m, p=p) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) - comp_mp = aamp(pd.Series(T_B), m, p=p) - naive.replace_inf(comp_mp) + cmp_mp = aamp(pd.Series(T_B), m, p=p) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -51,17 +51,17 @@ def test_aamp_A_B_join(T_A, T_B): m = 3 for p in [1.0, 2.0, 3.0]: ref_mp = naive.aamp(T_A, m, T_B=T_B, p=p) - comp_mp = aamp(T_A, m, T_B, ignore_trivial=False, p=p) + cmp_mp = aamp(T_A, m, T_B, ignore_trivial=False, p=p) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) - comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False, p=p) - naive.replace_inf(comp_mp) + cmp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False, p=p) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -69,17 +69,17 @@ def test_aamp_constant_subsequence_self_join(): T_A = np.concatenate((np.zeros(20, dtype=np.float64), np.ones(5, dtype=np.float64))) m = 3 ref_mp = naive.aamp(T_A, m) - comp_mp = aamp(T_A, m, ignore_trivial=True) + cmp_mp = aamp(T_A, m, ignore_trivial=True) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices - comp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True) - naive.replace_inf(comp_mp) + cmp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices @@ -88,26 +88,26 @@ def test_aamp_one_constant_subsequence_A_B_join(): T_B = np.concatenate((np.zeros(20, dtype=np.float64), np.ones(5, dtype=np.float64))) m = 3 ref_mp = naive.aamp(T_A, m, T_B=T_B) - comp_mp = aamp(T_A, m, T_B, ignore_trivial=False) + cmp_mp = aamp(T_A, m, T_B, ignore_trivial=False) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices - comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) - naive.replace_inf(comp_mp) + cmp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices # Swap inputs ref_mp = naive.aamp(T_B, m, T_B=T_A) - comp_mp = aamp(T_B, m, T_A, ignore_trivial=False) + cmp_mp = aamp(T_B, m, T_A, ignore_trivial=False) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices @@ -118,32 +118,32 @@ def test_aamp_two_constant_subsequences_A_B_join(): T_B = np.concatenate((np.zeros(20, dtype=np.float64), np.ones(5, dtype=np.float64))) m = 3 ref_mp = naive.aamp(T_A, m, T_B=T_B) - comp_mp = aamp(T_A, m, T_B, ignore_trivial=False) + cmp_mp = aamp(T_A, m, T_B, ignore_trivial=False) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices - comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) - naive.replace_inf(comp_mp) + cmp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices # Swap inputs ref_mp = naive.aamp(T_B, m, T_B=T_A) - comp_mp = aamp(T_B, m, T_A, ignore_trivial=False) + cmp_mp = aamp(T_B, m, T_A, ignore_trivial=False) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices - comp_mp = aamp(pd.Series(T_B), m, pd.Series(T_A), ignore_trivial=False) - naive.replace_inf(comp_mp) + cmp_mp = aamp(pd.Series(T_B), m, pd.Series(T_A), ignore_trivial=False) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5e-07 ) # ignore indices @@ -154,19 +154,19 @@ def test_aamp_identical_subsequence_self_join(): T_A[11 : 11 + identical.shape[0]] = identical m = 3 ref_mp = naive.aamp(T_A, m) - comp_mp = aamp(T_A, m, ignore_trivial=True) + cmp_mp = aamp(T_A, m, ignore_trivial=True) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices - comp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True) - naive.replace_inf(comp_mp) + cmp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices @@ -180,30 +180,30 @@ def test_aamp_identical_subsequence_A_B_join(): T_B[11 : 11 + identical.shape[0]] = identical m = 3 ref_mp = naive.aamp(T_A, m, T_B=T_B) - comp_mp = aamp(T_A, m, T_B, ignore_trivial=False) + cmp_mp = aamp(T_A, m, T_B, ignore_trivial=False) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices - comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) - naive.replace_inf(comp_mp) + cmp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices # Swap inputs ref_mp = naive.aamp(T_B, m, T_B=T_A) - comp_mp = aamp(T_B, m, T_A, ignore_trivial=False) + cmp_mp = aamp(T_B, m, T_A, ignore_trivial=False) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp[:, 0].astype(np.float64), + cmp_mp[:, 0].astype(np.float64), ref_mp[:, 0].astype(np.float64), atol=1.5 * 10**-config.STUMPY_TEST_PRECISION, ) # ignore indices @@ -222,17 +222,17 @@ def test_aamp_nan_inf_self_join(T_A, T_B, substitute_B, substitution_locations): T_B_sub[substitution_location_B] = substitute_B ref_mp = naive.aamp(T_B_sub, m) - comp_mp = aamp(T_B_sub, m, ignore_trivial=True) + cmp_mp = aamp(T_B_sub, m, ignore_trivial=True) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) - comp_mp = aamp(pd.Series(T_B_sub), m, ignore_trivial=True) - naive.replace_inf(comp_mp) + cmp_mp = aamp(pd.Series(T_B_sub), m, ignore_trivial=True) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -256,19 +256,19 @@ def test_aamp_nan_inf_A_B_join( T_B_sub[substitution_location_B] = substitute_B ref_mp = naive.aamp(T_A_sub, m, T_B=T_B_sub) - comp_mp = aamp(T_A_sub, m, T_B_sub, ignore_trivial=False) + cmp_mp = aamp(T_A_sub, m, T_B_sub, ignore_trivial=False) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) - comp_mp = aamp( + cmp_mp = aamp( pd.Series(T_A_sub), m, pd.Series(T_B_sub), ignore_trivial=False ) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -277,12 +277,12 @@ def test_aamp_nan_zero_mean_self_join(): m = 3 ref_mp = naive.aamp(T, m) - comp_mp = aamp(T, m, ignore_trivial=True) + cmp_mp = aamp(T, m, ignore_trivial=True) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -292,17 +292,17 @@ def test_aamp_self_join_KNN(T_A, T_B): for k in range(2, 4): for p in [1.0, 2.0, 3.0]: ref_mp = naive.aamp(T_B, m, p=p, k=k) - comp_mp = aamp(T_B, m, p=p, k=k) + cmp_mp = aamp(T_B, m, p=p, k=k) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) - comp_mp = aamp(pd.Series(T_B), m, p=p, k=k) - naive.replace_inf(comp_mp) + cmp_mp = aamp(pd.Series(T_B), m, p=p, k=k) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) @@ -312,17 +312,17 @@ def test_aamp_A_B_join_KNN(T_A, T_B): for k in range(2, 4): for p in [1.0, 2.0, 3.0]: ref_mp = naive.aamp(T_A, m, T_B=T_B, p=p, k=k) - comp_mp = aamp(T_A, m, T_B, ignore_trivial=False, p=p, k=k) + cmp_mp = aamp(T_A, m, T_B, ignore_trivial=False, p=p, k=k) naive.replace_inf(ref_mp) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 ) - comp_mp = aamp( + cmp_mp = aamp( pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False, p=p, k=k ) - naive.replace_inf(comp_mp) + naive.replace_inf(cmp_mp) npt.assert_allclose( - comp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 + cmp_mp.astype(np.float64), ref_mp.astype(np.float64), atol=1.5e-07 )