On Sat, Dec 28, 2019 at 3:40 PM David Mertz <me...@gnosis.cx> wrote:

> What about Decimal snan?
>

That version tries to call .is_nan() first, so works fine with the Decimal
snan.

But as Nark pointed out, having an s an raise maybe the right thing to do
anyway— it should not be used to indicate a missing value anyway.

I’m pretty sure the issue with numpy array scalars is that it’s not calling
__float__.

Which does make think that maybe all __float__ implementations should
return a float NaN when appropriate.

-CHB





>
> On Sat, Dec 28, 2019, 5:53 PM Christopher Barker <python...@gmail.com>
> wrote:
>
>> 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/
>>
> --
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/XA2WSUXRAERUX2U4WZJ6FVNUO5JHHWYX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to