Minor bug in Olea

Issue #67 resolved
Former user created an issue

The method Olea._gen_vp() contains the following section:

try:
    if p == 0:
        yield (0,1)
        return
    if p == 1:
        yield (n,1)
        return
except:
    pass

The variable p is not defined - you probably meant self.p.

The NameError that would normally be produced is being ignored because of the try…except. You should probably remove this, it’s almost never a good idea to ignore all errors like this.

(By the way, Bitbucket issues seem dreadfully broken - I couldn't submit this issue in Firefox.)

Comments (6)

  1. Pierre Denis repo owner
    • changed status to open

    Well spotted! The issue can be visible in corner cases like

    lea.binom(4, 0.0)
    

    which displays entries with probabilities 0 and

    lea.binom(4, 1.0)
    

    which causes a ZeroDivisonError.

    The odd try: except; construct was meant to prevent issues if probability is symbolic, i.e. a SymPy variable. After checks, this try: except; can be removed because both tests equating a SympPy variable with 0 or 1 return False, which is exactly what is needed.

    Independently of the present issue, the p attribute should better be renamed, so to avoid a name collision with method p(…) defined on any Lea instance.

    Many thanks for reporting this!

    This will be fixed in next Lea version.

  2. Log in to comment