[Python-Dev] PyObject_RichCompareBool identity shortcut
Steven D'Aprano
steve at pearwood.info
Thu Apr 28 19:25:08 CEST 2011
Alexander Belopolsky wrote:
> With the status quo in Python, it may only make sense to store NaNs in
> array.array, but not in a list.
That's a bit extreme. It only gets you into trouble if you reason like this:
>>> a = b = [1, 2, 3, float('nan')]
>>> if a == b:
... for x,y in zip(a,b):
... assert x==y
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
AssertionError
But it's perfectly fine to do this:
>>> sum(a)
nan
exactly as expected. Prohibiting NANs from lists is massive overkill for
a small (alleged) problem.
I know thousands of words have been spilled on this, including many by
myself, but I really believe this discussion is mostly bike-shedding.
Given the vehemence of some replies, and the volume of talk, anyone
would think that you could hardly write a line of Python code without
badly tripping over problems caused by NANs. The truth is, I think, that
most people will never see one in real world code, and those who are
least likely to come across them are the most likely to be categorically
against them.
(I grant that Alexander is an exception -- I understand that he does do
a lot of numeric work, and does come across NANs, and still doesn't like
them one bit.)
--
Steven
More information about the Python-Dev
mailing list