[Biopython-dev] float('inf') or float('-inf')

Peter Cock p.j.a.cock at googlemail.com
Sun Jun 5 21:51:26 UTC 2011

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:

This is the root cause of this unit test failure on Windows Python 2.5,

ERROR: Test a simple model with 2 states and 2 symbols.
Traceback (most recent call last):
  File "c:\repositories\BuildBot\win25\build\Tests\test_HMMGeneral.py",
line 260, in test_simple_hmm
    viterbi = model.viterbi(observed_emissions, NumberAlphabet)
  File "c:\repositories\BuildBot\win25\build\build\lib.win32-2.5\Bio\HMM\MarkovModel.py",
line 499, in viterbi
    log_initial = self._log_transform(self.initial_prob)
  File "c:\repositories\BuildBot\win25\build\build\lib.win32-2.5\Bio\HMM\MarkovModel.py",
line 598, in _log_transform
    neg_inf = float("-inf")
ValueError: invalid literal for float(): -inf

and similarly on Windows Python 2.4,

This test failure is a result of me committing Walter Gillett's
fix to Txt Bio/HMM/MarkovModel.py last week:

We would have spotted this earlier, but the Windows buildslave
machine has been in use by a new staff member (a temporary
arrangement). I guess we need more volunteer buildslave

Based on the PEP 754 example, 1E400 may work instead:

    neg_inf = float("-inf")
except ValueError:
    neg_inf =  -1E400

I'll try to test this on the machine later in the week when I get
a chance. If anyone else has Python 2.4 or 2.5 on Windows
and wants to look at this now, please go ahead.



More information about the Biopython-dev mailing list