You could check if each of them is NaN separately. To do that, I suggest using the following class:
import math
class NumericAssertions:
"""
This class is following the UnitTest naming conventions.
It is meant to be used along with unittest.TestCase like so :
class MyTest(unittest.TestCase, NumericAssertions):
...
It needs python >= 2.6
"""
def assertIsNaN(self, value, msg=None):
"""Fail if provided value is not NaN"""
standardMsg = "%s is not NaN" % str(value)
try:
if not math.isnan(value):
self.fail(self._formatMessage(msg, standardMsg))
except:
self.fail(self._formatMessage(msg, standardMsg))
def assertIsNotNaN(self, value, msg=None):
"""Fail if provided value is NaN"""
standardMsg = "Provided value is NaN"
try:
if math.isnan(value):
self.fail(self._formatMessage(msg, standardMsg))
except:
pass
It would be as easy as:
v1 = np.nan
v2 = np.nan
self.assertIsNaN(v1)
self.assertIsNaN(v2)
assertBothNan
, or overrideassertEquals
if you always want that behaviour. As to how you check if a value is NaN: https://mcmap.net/q/420894/-how-to-check-if-value-is-nan-in-unittest/3001761 – Ossav1==v2
will be False. You should check that both are Nan separately and then write your own assertion method. – Jaclyn