+1 for a .is_nan() method on suitable types. That's the most natural
and elegant solution, IMHO. Tricks like "x == x" are nice when you
*know* that x is a float or Decimal, but not in the general case.
agreed -- while it may work in almost all cases, what it is really checking is whether an object compares to itself, which is not question being asked.
I suppose we could do something like:
def is_nan(num):
try:
return num.is_nan()
except AttributeError:
if isinstance(num, Number):
return not (num == num)
else:
return False
Running it on my test code, it works for everything I thought to test except numpy arrays of size 1.
-CHB
--
Christopher Barker, PhD
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython
--
Christopher Barker, PhD
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython