Returns True if a and b are equal up to decimal places. If fill_value is True, masked values considered equal. Otherwise, masked values are considered unequal.
(a, b, decimal=6, fill_value=True)
| 61 | |
| 62 | |
| 63 | def almost(a, b, decimal=6, fill_value=True): |
| 64 | """ |
| 65 | Returns True if a and b are equal up to decimal places. |
| 66 | |
| 67 | If fill_value is True, masked values considered equal. Otherwise, |
| 68 | masked values are considered unequal. |
| 69 | |
| 70 | """ |
| 71 | m = mask_or(getmask(a), getmask(b)) |
| 72 | d1 = filled(a) |
| 73 | d2 = filled(b) |
| 74 | if d1.dtype.char == "O" or d2.dtype.char == "O": |
| 75 | return np.equal(d1, d2).ravel() |
| 76 | x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_) |
| 77 | y = filled(masked_array(d2, copy=False, mask=m), 1).astype(float_) |
| 78 | d = np.around(np.abs(x - y), decimal) <= 10.0 ** (-decimal) |
| 79 | return d.ravel() |
| 80 | |
| 81 | |
| 82 | def _assert_equal_on_sequences(actual, desired, err_msg=''): |