Repository navigation
Description
Is your feature request related to a problem?
The testing code uses pytest and relies on numpy.testing. It contains some deprecated testing constructs such as assert_almost_equal(), assert_array_almost_equal() and some sub-optimal tests (such as testing single floats with an array assertion).
Describe the solution you'd like
Update the testing code, following current best practices, such as
- use
numpy.testing.assert_allclose()instead ofassert_almost_equal()orassert_array_almost_equal()for more consistent floating point comparisons - replace array comparisons for floating point scalars (a single floating point number) with
pytest.approx()(see Nuclinfo Major Pair and Minor Pair overhaul #3735 (comment)) - ...
Please add additional best practices here or in the comments.
Describe alternatives you've considered
We don't have to do anything right now because everything is working.
How to work on this issue
You can open issues for individual points above, you don't have to work on all of them. If you create a new issue, mention this issue number in the issue text so that it gets linked.
Find occurrences of the constructs that you want to change in the code, e.g.,
cd testsuite/
git grep 'assert_almost_equal'Figure out how to change the code to get an equivalent result by learning about the different arguments that the old and the new function take and how they affect the assertion. Then pick one example and implement your solution. See if it works. Improve your example until it works. Only then start converting more of the test files. Get feedback from other developers.
Activity
utkarsh147-del commentedon Jul 9, 2022
i want to work on this issue
orbeckst commentedon Jul 9, 2022
We always welcome contributions. Just submit a PR that references this issue. We will then discuss there. When you start the work, please also introduce you on the developer mailing list.
Btw, we don’t “reserve” work, we just look at the first PR that addresses the issue. Details of our policy are in our GSOC FAQ on our wiki.
rzhao271 commentedon Jul 23, 2022
I tried converting more tests to use
assert_allcloseinstead ofassert_almost_equals, but an issue I've run into is that for scalars,pytest.approxdoesn't work well when the original test had a custom error message.Here's how the signature looks for
assert_almost_equals:assert_almost_equals(a, b, rtol=0, atol=something, err_msg=something)But for
pytest.approx, one uses it as follows:assert a == approx(b, abs=something)I'm wondering if I can just use
assert_allcloseinstead? Otherwise I'd have to write something likefor those tests.
orbeckst commentedon Jul 23, 2022
Does
work?
Ranit-Bandyopadhyay commentedon Jan 16, 2023
hello, i want to work on this project.
orbeckst commentedon Jan 16, 2023
Hello @Ranit-Bandyopadhyay , if no-body else is working on an issue as evidenced by a linked PR, just go ahead an submit a PR. See also our GSOC FAQ https://github.com/MDAnalysis/mdanalysis/wiki/GSoC-FAQ#can-i-claim-an-issue-to-work-on .
chandra20500 commentedon Feb 10, 2023
Hi, I would like to work on this Issue. it would be great could you please assign this issue to me
orbeckst commentedon Feb 10, 2023
@chandra20500 , see what I said above and read the link to the FAQ: we do not reserve or assign issues. We just evaluate work presented.
utkarsh147-del commentedon Feb 12, 2023
can u tell me the link of testing code
hmacdope commentedon Feb 12, 2023
@utkarsh147-del you can find the link by reading the User Guide
22 remaining items
Modernize assertions in test_distances.py (part of MDAnalysis#3743)
Modernize assertions in test_gnm.py (part of MDAnalysis#3743)
Modernize assertions in test_distances.py (part of #3743) (#5158)
Modernize assertions in test_density.py (Contributes to #3743) (#5155)
Fixes MDAnalysis#3743: Modernize test assertions in test_msd.py
Fixes MDAnalysis#3743: Modernize test assertions in test_msd.py
tests: modernize deprecated numpy assertions in test_gnm.py (ref MDAn…
deekshithdeekshith020-ux commentedon Dec 20, 2025
hey team , is there any remaining work that need to be done here , i want to contribute to md analysis and its my first contribution please guide me assign me to this do this work. so in simple words the problem here is : From my understanding, the goal is to replace the current raw assert statements in the test suite with NumPy’s dedicated testing functions (such as np.testing.assert_equal, np.testing.assert_allclose, etc.), so that numerical and array comparisons become more reliable and consistent with best practices.
I plan to start by locating such asserts in the tests, update them gradually, and verify using pytest that everything still passes.
Please let me know if this plan sounds good or if there are any preferred files to begin with 😊@orbeckst sir.
marinegor commentedon Dec 23, 2025
@deekshithdeekshith020-ux
I'd suggest familiarizing yourself with the contribution guide here: https://userguide.mdanalysis.org/stable/contributing.html
For this particular issue, I'd suggest checking some associated PRs (e.g. #5156) and do a similar body of work.
Kd1880 commentedon Mar 5, 2026
Hi! I'm new to MDAnalysis and interested in contributing.
I'd like to work on this issue if it's still available.
Fix MDAnalysis#3743: replace assert_almost_equal with assert_allclose…
Update AUTHORS and CHANGELOG for MDAnalysis#3743
tests: modernize deprecated numpy assertions in test_gnm.py (ref #3743)…
tests: modernize deprecated numpy assertions in test_helix_analysis.p…
tests: modernize deprecated numpy assertions in test_helix_analysis.p…