On Sat, Dec 28, 2019 at 2:41 AM Antoine Pitrou <solip...@pitrou.net> wrote:
> +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
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/WYRLHSVZTPE756XXGHDXW2HK624DPW5P/ Code of Conduct: http://python.org/psf/codeofconduct/