[Biopython-dev] float('nan') fails on Python 2.5 on Windows (PAML)

Peter Cock p.j.a.cock at googlemail.com
Fri Jul 22 17:36:46 UTC 2011


On Thu, Jul 21, 2011 at 9:48 PM, Peter Cock <p.j.a.cock at googlemail.com> wrote:
> On Sun, Jun 5, 2011 at 10:51 PM, Peter wrote:
>> Hi all,
>>
>> As explained in PEP 754, prior to Python 2.6 float('inf'), float('-inf')
>> and also float('nan') were passed to the underlying C library, which
>> may or may not return the IEEE special floating point value for
>> infinity, minus infinity or nan. See:
>> http://www.python.org/dev/peps/pep-0754/
>>
>> This is the root cause of this unit test failure on Windows Python 2.5,
>> ...
>
> The related problem of float("nan") on Python 2.5 or older on
> Windows is the cause of this problem in the new PAML code too:
>
> http://testing.open-bio.org/biopython/builders/Windows%20XP%20-%20Python%202.5/builds/229/steps/shell/logs/stdio
>
> ValueError: invalid literal for float(): nan
>
> I guess _parse_codeml.py might need something like this:
>
>
> try:
>    float("nan")
>    _float = float
> except ValueError:
>    def _float(txt):
>        try:
>            return float(text)
>        except ValueError, e:
>            if txt=="nan":
>                return XXX
>            else:
>                raise e
>
> And then use the nan safe _float function in the parser.
>
> Unless anyone has a nicer solution?
>
> Peter

I've committed something like that after testing on Windows,
https://github.com/biopython/biopython/commit/7539e9163839642ada24e1ebb9c3aff1bb25d573

Not very elegant, but it works.

Peter




More information about the Biopython-dev mailing list