On Sun, Dec 29, 2019 at 08:22:49AM -0500, David Mertz wrote:
> Signalling NaN's are a pain because I'd want:
> 
> is_nan(snan) == True
> 
> But statistics.median([1, 2, snan], on_nan='ignore') to raise an exception.

So you want to skip quiet NANs and raise on signalling NANs?

I'd like to understand the use-case here. I guess it is "signalling NANs 
are an error, quiet NANs are missing data". Am I right?

How are the signalling NANs going to get into your data?

As far as I know, there are no operations in Python which will naturally 
return a signalling NAN, you have to inject them into the data yourself:

(1) The float() constructor doesn't accept "snan"; no arithmetic 
operations or math module libraries return signalling NANs, so the only 
way to create a sNAN is using the struct module. But that's not 
guaranteed to succeed: as per the link I gave earlier

https://mail.python.org/archives/list/python-...@python.org/thread/35NECLGFIVAHWTIPAYDBJOJJX3FSY233/

that's platform-dependent. So there's no platform-independent way to get 
a float sNAN, or guarantee that it will work the way you want.

(2) The Decimal constructor does accept "snan", and it it platform- 
independent. But as far as I can tell there's no way to get a sNAN out 
as the result of any Decimal operation. Invalid operations will either 
return a quiet NAN, or raise.

Either way, float or Decimal, the only way to get a sNAN in your data is 
to put it there yourself. Why not just raise at the point of inserting 
the ~~landmine~~ sNAN instead?

Alternately, could you use None or object()? With the exception of mode, 
the statistics functions will fail with TypeError.



-- 
Steven
_______________________________________________
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/36Q6O3DBMD5L45PHDBVRZ4ONI6WUW5VV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to