I dug the source code and found out what was going on. In the end, the decimal_almost_equal function is decimal_almost_equal , which looks like this in normal Python (in Cython).
def decimal_almost_equal(desired, actual, decimal): return abs(desired - actual) < (0.5 * 10.0 ** -decimal)
See the source code here. Here is the actual function call:
decimal_almost_equal(1, fb / fa, decimal)
Where in this example
fa = .1 fb = .12 decimal = 1
So the function call becomes
decimal_almost_equal(1, 1.2, 1)
Which decimal_almost_equal evaluates to
abs(1 - 1.2) < .5 * 10 ** -1
or
.2 < .05
What is False .
Thus, the comparison is based on a percentage difference, not a total difference.
If you want an absolute comparison, check out np.allclose .
np.allclose(expected, output, atol=.1) True
source share