Skip to content

Commit

Permalink
Bugfix for NaN-safe equality checks in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Jan 30, 2024
1 parent d95b8e5 commit 5721e67
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def assert_identical_ndarrays(x: numpy.ndarray, y: numpy.ndarray):

def is_equal_with_nan(left: numpy.ndarray, right: numpy.ndarray):
if numpy.issubdtype(left.dtype, numpy.floating) or numpy.issubdtype(right.dtype, numpy.floating):
return numpy.logical_or(numpy.isnan(left) == numpy.isnan(right), left == right)
lnan = numpy.isnan(left)
return numpy.logical_and(lnan == numpy.isnan(right), numpy.logical_or(lnan, left == right))
else:
return left == right

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

def is_close_with_nan(left: numpy.ndarray, right: numpy.ndarray):
if numpy.issubdtype(left.dtype, numpy.floating) or numpy.issubdtype(right.dtype, numpy.floating):
return numpy.logical_or(numpy.isnan(left) == numpy.isnan(right), numpy.isclose(left, right))
lnan = numpy.isnan(left)
return numpy.logical_and(lnan == numpy.isnan(right), numpy.logical_or(lnan, numpy.isclose(left, right)))
else:
return numpy.isclose(left, right)

Expand Down

0 comments on commit 5721e67

Please sign in to comment.