Skip to content
Snippets Groups Projects
Commit 194fd5de authored by leufen1's avatar leufen1
Browse files

adjusted helper function to work for single numbers with precision

parent 97631614
No related branches found
No related tags found
4 merge requests!432IOA works now also with xarray and on identical data, IOA is included in...,!431Resolve "release v2.1.0",!430update recent developments,!415Resolve "add metric IOA"
Pipeline #99520 failed
......@@ -140,6 +140,14 @@ def check_nested_equality(obj1, obj2, precision=None):
else:
print(f"check np {obj1} and {obj2} with precision {precision}")
assert np.testing.assert_array_almost_equal(obj1, obj2, decimal=precision) is None
else:
if isinstance(obj1, (int, float)) and isinstance(obj2, (int, float)):
if precision is None:
print(f"check number equal {obj1} and {obj2}")
assert np.testing.assert_equal(obj1, obj2) is None
else:
print(f"check number equal {obj1} and {obj2} with precision {precision}")
assert np.testing.assert_almost_equal(obj1, obj2, decimal=precision) is None
else:
print(f"check equal {obj1} and {obj2}")
assert obj1 == obj2
......
......@@ -58,14 +58,14 @@ class TestNestedEquality:
assert check_nested_equality("3", 3) is False
assert check_nested_equality("3", "3") is True
assert check_nested_equality(None, None) is True
assert check_nested_equality(3.91, 3.9, 1) is True
assert check_nested_equality(3.91, 3.9, 2) is False
assert check_nested_equality(3.92, 3.9, 1) is True
assert check_nested_equality(3.92, 3.9, 2) is False
def test_nested_equality_xarray(self):
obj1 = xr.DataArray(np.random.randn(2, 3), dims=('x', 'y'), coords={'x': [10, 20], 'y': [0, 10, 20]})
obj2 = xr.ones_like(obj1) * obj1
assert check_nested_equality(obj1, obj2) is True
obj2 = 1.0001 * obj2
obj2 = obj2 * 1.0001
assert check_nested_equality(obj1, obj2) is False
assert check_nested_equality(obj1, obj2, 3) is True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment