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)
| 67 | |
| 68 | |
| 69 | def almost(a, b, decimal=6, fill_value=True): |
| 70 | """ |
| 71 | Returns True if a and b are equal up to decimal places. |
| 72 | |
| 73 | If fill_value is True, masked values considered equal. Otherwise, |
| 74 | masked values are considered unequal. |
| 75 | |
| 76 | """ |
| 77 | m = mask_or(getmask(a), getmask(b)) |
| 78 | d1 = filled(a) |
| 79 | d2 = filled(b) |
| 80 | if d1.dtype.char == "O" or d2.dtype.char == "O": |
| 81 | return np.equal(d1, d2).ravel() |
| 82 | x = filled( |
| 83 | masked_array(d1, copy=False, mask=m), fill_value |
| 84 | ).astype(np.float64) |
| 85 | y = filled(masked_array(d2, copy=False, mask=m), 1).astype(np.float64) |
| 86 | d = np.around(np.abs(x - y), decimal) <= 10.0 ** (-decimal) |
| 87 | return d.ravel() |
| 88 | |
| 89 | |
| 90 | def _assert_equal_on_sequences(actual, desired, err_msg=''): |