[Python-ideas] Disallow orderring comparison to NaN
Nick Coghlan
ncoghlan at gmail.com
Fri Apr 29 09:00:48 CEST 2011
On Fri, Apr 29, 2011 at 8:10 AM, Guido van Rossum <guido at python.org> wrote:
> On Thu, Apr 28, 2011 at 12:25 PM, Alexander Belopolsky
> <alexander.belopolsky at gmail.com> wrote:
>> I posted a patch implementing this proposal on the tracker:
>>
>> http://bugs.python.org/issue11949
>
> Interesting indeed! I'd like to hear from the numpy folks about this.
>
> But isn't a similar change needed for Decimal?
decimal already works that way:
>>> from decimal import Decimal as d
>>> nan = d("nan")
>>> nan
Decimal('NaN')
>>> nan < 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python32\lib\decimal.py", line 887, in __lt__
ans = self._compare_check_nans(other, context)
File "C:\Python32\lib\decimal.py", line 788, in _compare_check_nans
self)
File "C:\Python32\lib\decimal.py", line 3926, in _raise_error
raise error(explanation)
decimal.InvalidOperation: comparison involving NaN
+1 from me for making float NaNs raise ValueError for ordering comparisons.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list