Skip to content

Migrate tests from npt.assert_almost_equal to npt.assert_allclose - #1178

Open
viknesh-ai wants to merge 1 commit into
stumpy-dev:mainfrom
viknesh-ai:fix/1175-migrate-to-assert-allclose
Open

Migrate tests from npt.assert_almost_equal to npt.assert_allclose#1178
viknesh-ai wants to merge 1 commit into
stumpy-dev:mainfrom
viknesh-ai:fix/1175-migrate-to-assert-allclose

Conversation

@viknesh-ai

@viknesh-ai viknesh-ai commented Aug 9, 2026

Copy link
Copy Markdown

Fixes #1175

npt.assert_almost_equal only checks a fixed absolute tolerance (abs(actual-desired) < 1.5 * 10**-decimal), and NumPy's own docs recommend assert_allclose instead for more consistent floating-point comparisons.

Migrated every call site to assert_allclose(a, b, atol=, rtol=0) — rtol=0 keeps it a pure absolute-tolerance check, so today's exact pass/fail behavior is preserved, just via the non-deprecated API.

A subset of comparisons (matrix profile output, match/motifs results, stumpi KNN state) combine a float distance column with an int index column, so they end up dtype=object. np.isclose can't handle object dtype the way assert_almost_equal can, so those specific sites were left on assert_almost_equal rather than force the migration. Confirmed this is genuinely data-dependent (not just "avoid P_/I_ everywhere") by running the suite the same way test.sh coverage does — one pytest process per file, JIT disabled, CUDA simulated — and only reverting the sites that actually broke.

Pull Request Checklist

Below is a simple checklist but please do not hesitate to ask for assistance!

  • Read our Contributing Guide
  • Referenced a Github issue (or create one if one doesn't already exist)
  • Read and reviewed all of the comments in the Github issue that you've referenced (along with cross-referenced issues/pull requests) to ensure that the issue still requires a pull request
  • Checked that the issue has not already been assigned to anybody else or is already being addressed in another pull request
  • Left a meaningful comment on the original Github issue to discuss the detailed approach for your contribution and received confirmation from the maintainers before proceeding with this pull request
  • Forked, cloned, and checked out the newest version of the code
  • Created a new branch
  • Made necessary code changes
  • Installed black (i.e., python -m pip install black or conda install -c conda-forge black)
  • Installed flake8 (i.e., python -m pip install flake8 or conda install -c conda-forge flake8)
  • Installed pytest-cov (i.e., python -m pip install pytest-cov or conda install -c conda-forge pytest-cov)
  • Ran black --exclude=".*\.ipynb" --extend-exclude=".venv" --diff ./ in the root stumpy directory
  • Ran flake8 --extend-exclude=.venv ./ in the root stumpy directory
  • Ran ./setup.sh dev && ./test.sh in the root stumpy directory and ensured that all tests are passing locally
  • Check this box if AI code assistance was used to generate 15%+ of the code in this pull request

npt.assert_almost_equal only checks a fixed absolute tolerance
(abs(actual-desired) < 1.5 * 10**-decimal), which NumPy's own docs
recommend against in favor of assert_allclose. Swap every call site
to assert_allclose(a, b, atol=<same threshold>, rtol=0), which
preserves today's exact pass/fail behavior with zero risk.

A few hundred call sites compare arrays that combine a float
distance column with an int index column (matrix profile output,
match/motifs results, stumpi KNN state). Those end up dtype=object,
and np.isclose can't handle object dtype the way assert_almost_equal
can, so those specific comparisons are left on assert_almost_equal.
Verified this is genuinely data-dependent (not just "avoid P_/I_
everywhere") by running the full suite the same way test.sh coverage
does - one pytest process per file, JIT disabled, CUDA simulated -
and reverting only the sites that actually broke.

Fixes stumpy-dev#1175
@viknesh-ai
viknesh-ai requested a review from seanlaw as a code owner August 9, 2026 17:41
@gitnotebooks

gitnotebooks Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review these changes at https://app.gitnotebooks.com/stumpy-dev/stumpy/pull/1178

@seanlaw seanlaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of submitting a single PR that touches 38 files at once, let's split this into one PR per test file. Only submit a new PR after the last PR gets merged (i.e., do NOT submit 38 PRs all at the same time).

Also, please ensure that:

  1. Each test file correctly replaces all uses of npt.assert_almost_equal with its equivalent npt.assert_allclose
  2. When rtol=0 for npt.assert_allclose, simply omit this paramter and value since this is the default

Comment thread tests/test_aamp.py
@@ -132,13 +132,17 @@ def test_aamp_identical_subsequence_self_join():
naive.replace_inf(ref_mp)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

Comment thread tests/test_aamp.py

comp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

Comment thread tests/test_aamp.py
@@ -154,13 +158,17 @@ def test_aamp_identical_subsequence_A_B_join():
naive.replace_inf(ref_mp)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

Comment thread tests/test_aamp.py

comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

Comment thread tests/test_aamp.py
@@ -169,7 +177,9 @@ def test_aamp_identical_subsequence_A_B_join():
naive.replace_inf(ref_mp)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

Comment thread tests/test_aamped.py
@@ -285,7 +285,9 @@ def test_aamped_identical_subsequence_self_join(dask_cluster):
naive.replace_inf(ref_mp)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

Comment thread tests/test_aamped.py
@@ -308,7 +310,9 @@ def test_aamped_identical_subsequence_A_B_join(dask_cluster):
naive.replace_inf(ref_mp)
naive.replace_inf(comp_mp)
npt.assert_almost_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate to npt.assert_allclose

2 participants