ANN: stats 0.1a calculator statistics for Python

Chris Torek nospam at torek.net
Tue Oct 19 14:22:42 CEST 2010


>2010/10/17 Steven D'Aprano <steve at remove-this-cybersource.com.au>:
>> http://pypi.python.org/pypi/stats

In article <mailman.23.1287437081.15964.python-list at python.org>
Vlastimil Brom  <vlastimil.brom at gmail.com> wrote:
>Thanks for this useful module!
>I just wanted to report a marginal error triggered in the doctests:
>
>Failed example:
>    isnan(float('nan'))
>Exception raised:
>    Traceback (most recent call last):
>      File "C:\Python25\lib\doctest.py", line 1228, in __run
>        compileflags, 1) in test.globs
>      File "<doctest __main__.isnan[0]>", line 1, in <module>
>        isnan(float('nan'))
>    ValueError: invalid literal for float(): nan
>
>(python 2.5.4 on win XP; this might be OS specific; probably in the
>newer versions float() was updated, the tests on 2.6 and 2.7 are ok ):

Indeed it was; in older versions float() just invoked the C library
routines, so float('nan') works on Mac OS X python 2.5, for instance,
but then you run into the fact that math.isnan() is only in 2.6 and
later :-)

Workaround, assuming an earlier "from math import *":

    try:
        isnan(0.0)
    except NameError:
        def isnan(x): x != x

Of course you are still stuck with float('nan') failing on Windows.
I have no quick and easy workaround for that one.
-- 
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)      http://web.torek.net/torek/index.html



More information about the Python-list mailing list