Fixed #1175 Migrate tests/test_aamp.py to npt.assert_allclose - #1178
Conversation
|
Review these changes at https://app.gitnotebooks.com/stumpy-dev/stumpy/pull/1178 |
seanlaw
left a comment
There was a problem hiding this comment.
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:
- Each test file correctly replaces all uses of
npt.assert_almost_equalwith its equivalentnpt.assert_allclose - When
rtol=0fornpt.assert_allclose, simply omit this paramter and value since this is the default
| comp_mp = aamped(dask_client, T_A, m, ignore_trivial=True) | ||
| naive.replace_inf(ref_mp) | ||
| naive.replace_inf(comp_mp) | ||
| npt.assert_almost_equal( |
There was a problem hiding this comment.
Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?
There was a problem hiding this comment.
Same root cause as the test_aamp.py threads — will fix it the same way (cast to float64 before comparing). Per your note about splitting this into one PR per file, I've scoped this PR down to just test_aamp.py for now; test_aamped.py will get its own PR once this one's merged
| comp_mp = aamped(dask_client, T_A, m, T_B, ignore_trivial=False) | ||
| naive.replace_inf(ref_mp) | ||
| naive.replace_inf(comp_mp) | ||
| npt.assert_almost_equal( |
There was a problem hiding this comment.
Why is npt.assert_almost_equal still being used here instead of npt.assert_allclose?
There was a problem hiding this comment.
Same root cause as the test_aamp.py threads — will fix it the same way (cast to float64 before comparing). Per your note about splitting this into one PR per file, I've scoped this PR down to just test_aamp.py for now; test_aamped.py will get its own PR once this one's merged
…_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 stumpy-dev#1175, per review feedback.
d33405c to
eafcae4
Compare
seanlaw
left a comment
There was a problem hiding this comment.
Please ensure that npt.assert_allclose(actual, desired) always has the stumpy computed value as "actual" and the naive computation as "desired".
Currently, in many cases, I am seeing
npt.assert_allclose(
ref_mp.astype(np.float64),
cmp_mp.astype(np.float64),
atol=1.5e-07
)
but it should be flipped to:
npt.assert_allclose(
cmp_mp.astype(np.float64),
ref_mp.astype(np.float64),
atol=1.5e-07
)
Also, please be consistent and use atol=1.5e-07 rather than atol=1.5*10**-07
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.
Keep the reference to config.STUMPY_TEST_PRECISION instead of hardcoding its current value as a literal atol.
|
You've removed my edits in your original post so I am repeating it hear for other PRs: To Do List
|
|
@seanlaw all comments addressed and replied to — arg order flipped, atol literal style fixed, config.STUMPY_TEST_PRECISION reference restored, and 27/27 tests passing in both normal and CI-equivalent modes. Ready for another look whenever you have time. |
Rename comp_mp to cmp_mp so ref and cmp are both three letters.
seanlaw
left a comment
There was a problem hiding this comment.
@viknesh-ai Everything looks good. Is this ready to be merged?
Yes, this one's ready to merge on my end. Once it's merged, can I open the next PR for the next file in the migration? |
@viknesh-ai Yes, please and thank you. |
Fixed #1175
Per review feedback, split into one PR per test file - this one covers
tests/test_aamp.pyonly. Will open the next file's PR once this one merges.assert_almost_equalonly checks a fixed absolute tolerance and NumPy's docs recommendassert_allcloseinstead. Every comparison in this file is againstref_mp/cmp_mp(or a column slice of it), which combine a float distance column with int index columns and so come backdtype=object-np.isclosecan't handle that directly. Cast both sides tofloat64before comparing instead of leaving these on the deprecated API, since the values are always numeric so the cast is exact. All 27 call sites in this file are now onassert_allclose, none left behind.rtolis left at its default rather than pinned to0.To Do List
Standing checklist from @seanlaw for this migration, applies to every file in the split - status below is for
test_aamp.py:npt.assert_almost_equalwith its equivalentnpt.assert_allclosertol=0fornpt.assert_allclose, simply omit this parameter and value since this is the defaultnpt.assert_allclose(actual, desired)always has the stumpy computed value asactualand the naive computation asdesiredatol=1.5e-07rather thanatol=1.5*10**-071.5*10**-config.STUMPY_TEST_PRECISIONwithconfig.STUMPY_TEST_PRECISION = 1.5e-07(inconfig.py) - tracked as a follow-up, not part of this per-file migrationcmpinstead ofcompfor the computed/performant value, so it's the same length asref(comp_mp->cmp_mp)Pull Request Checklist
Below is a simple checklist but please do not hesitate to ask for assistance!
black(i.e.,python -m pip install blackorconda install -c conda-forge black)flake8(i.e.,python -m pip install flake8orconda install -c conda-forge flake8)pytest-cov(i.e.,python -m pip install pytest-covorconda install -c conda-forge pytest-cov)black --exclude=".*\.ipynb" --extend-exclude=".venv" --diff ./in the root stumpy directoryflake8 --extend-exclude=.venv ./in the root stumpy directory./setup.sh dev && ./test.shin the root stumpy directory and ensured that all tests are passing locallyPlease do not commit any code to avoid/circumvent a failing test and, instead, engage in a discussion (below) to determine the best course of action.
Only request a review after the checklist above is fully completed!