[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The NaNny State

This is not a complaint about python.


It is about the recent discussion about the concept and word "nan" as used
in python and elsewhere. As noted, the correct spelling in python is all
lower case as in "nan" with a minor exception that creating a nan using
float(string) allows any combination of cases such as string="nAN".


I like to learn and contrast languages to try to make some sense of things
and see different ways to conceptualize things. As discussed, there are
subtle uses of concepts such as NOT A NUMBER versus NOT AVAILABLE that often
get conflated. In Python, the math and numpy modules also include a nan
constant as in math.nan.


What is bothersome is the ways other places in a language spell the same or
related concept leading to confusion. If you read a CSV file using the
pandas module with pandas.read_csv() it shows empty items as "NaN". The
programming language JAVA spells it the same way to mean the result of
dividing zero by zero as Not a Number. The programming language R uses NA
for Not Available and uses NaN for Not a Number but also has constants that
test more specifically such as NA_integer_ and NA_character_ and you have
test functions like is.na() and is.nan() but just to be confusing is.na()
also returns TRUE when looking at a NaN!


I am sure we can look at other languages and get even more confused!


Now I am not saying which implementation is in some ways better, just
admiring the diversity of ways of looking at things that seem to happen as
many languages develop. I see other anomalies such as languages that have a
concept of both a negative and positive zero or different infinity types for
float versus double. There are so many themes you can look at across
languages that indicate there is no one totally obvious way.


So when people wonder why python does things in a way they are not seeing as
right, they need to wonder if dropping some preconceptions may let them
learn what the language DOES and adjust rather than fight it. Don't let the
NaNny state dictate what must be.