[Python-ideas] Suggestion: Extend integers to include iNaN
gadgetsteve at live.co.uk
Sat Sep 29 02:31:46 EDT 2018
One of the strengths of the IEEE float, (to set against its many
weaknesses), is the presence of the magic value NaN. Not a Number, or
NaA, is especially useful in that it is a valid value in any
mathematical operation, (always returning NaN), or comparison, (always
returning False). In functional programming this is especially useful as
it allows the chain to complete after an error while retaining the fact
that an error occurred, (as we got NaN).
In languages such as C integers can only be used to represent a limited
range of values in integers and a less limited range of values, (but
still limited), with a limited accuracy. However, one of Pythons
strengths is that its integers can represent any whole number value, (up
to the maximum available memory and in exchange for slow performance
when numbers get huge). This is accomplished by Python Integers being
objects rather than a fixed number of bytes.
I think that it should be relatively simple to extend the Python integer
class to have a NaN flag, possibly by having a bit length of 0, and have
it follow the same rules for the handling of floating point NaN, i.e.
any mathematical operation on an iNaN returns an iNaN and any comparison
with one returns False.
One specific use case that springs to mind would be for Libraries such
as Pandas to return iNaN for entries that are not numbers in a column
that it has been told to treat as integers.
We would possibly need a flag to set this behaviour, rather than raising
an Exception, or at the very least automatically (or provide a method
to) set LHS integers to iNaN on such an exception.
I thought that I would throw this out to Python Ideas for some
discussion of whether such a feature is:
b) Possible, (I am sure that it could be done)?
c) Likely to get me kicked off of the list?
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.
This email has been checked for viruses by AVG.
More information about the Python-ideas