numpy/pandas: test float64 arrays are equal up to significant digits

896 Views Asked by At

I have two pandas data frames in which I store money amounts, i.e. decimal numbers with at most 15 significant decimal digits. Since float64 has a precision of 15 significant decimal digits, this should be lossless.

How do I compare the values of two such dataframes for equivalence up to the 15 significant decimal digits?

In short, I am looking for something like numpy.testing.assert_approx_equal - which should however take numpy arrays as arguments rather than only scalars.

Another option would be to use a rounding function that can round to a given number of significant decimal digits rather than the usual decimal places.

1

There are 1 best solutions below

2
On

there's actually a numpy function for this:

np.allclose

definition/usage:

np.allclose(a, b, rtol=1e-05, atol=1e-08)