Skip to content

numpy/positional-tolerance

Rule positional-tolerance
Pack NumPy
Severity warning
Fix safe, with xpd check --fix
Library versions every version

The third argument of np.isclose and np.allclose is rtol, a relative tolerance, and many readers expect an absolute one. Name the argument, as rtol= or as atol= when an absolute tolerance was meant.

same = np.isclose(a, b, 1e-3)
same = np.isclose(a, b, atol=1e-3)

The rule reports np.isclose(a, b, 1e-3) and np.allclose(a, b, 1e-3). The third argument sets rtol, and atol stays 1e-8.

The rule leaves a call alone that also passes atol, or that passes a value named like rtol.

xpd check --fix applies the fix of this rule.

The safe fix writes np.isclose(a, b, rtol=1e-3), which names the parameter that the third argument already fills. Where an absolute tolerance was meant, change it to atol=. A call with a splat before the third argument has no fix.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

The third argument of $NP.$F is rtol, a relative tolerance, and atol stays 1e-8. Write rtol=$T, which keeps what the call does, and change it to atol=$T where an absolute tolerance was meant.

Browse the other rules of the NumPy pack.