Skip to content

Commit 5721e67

Browse files
committed
Bugfix for NaN-safe equality checks in tests.
1 parent d95b8e5 commit 5721e67

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tests/utils.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def assert_identical_ndarrays(x: numpy.ndarray, y: numpy.ndarray):
2929

3030
def is_equal_with_nan(left: numpy.ndarray, right: numpy.ndarray):
3131
if numpy.issubdtype(left.dtype, numpy.floating) or numpy.issubdtype(right.dtype, numpy.floating):
32-
return numpy.logical_or(numpy.isnan(left) == numpy.isnan(right), left == right)
32+
lnan = numpy.isnan(left)
33+
return numpy.logical_and(lnan == numpy.isnan(right), numpy.logical_or(lnan, left == right))
3334
else:
3435
return left == right
3536

@@ -48,7 +49,8 @@ def assert_close_ndarrays(x: numpy.ndarray, y: numpy.ndarray):
4849

4950
def is_close_with_nan(left: numpy.ndarray, right: numpy.ndarray):
5051
if numpy.issubdtype(left.dtype, numpy.floating) or numpy.issubdtype(right.dtype, numpy.floating):
51-
return numpy.logical_or(numpy.isnan(left) == numpy.isnan(right), numpy.isclose(left, right))
52+
lnan = numpy.isnan(left)
53+
return numpy.logical_and(lnan == numpy.isnan(right), numpy.logical_or(lnan, numpy.isclose(left, right)))
5254
else:
5355
return numpy.isclose(left, right)
5456

0 commit comments

Comments
 (0)