Skip to content

Truncated distributions define .var instead of .variance, so .variance raises NotImplementedError #2

Description

@tillahoffmann

Problem

Three public, exported truncated distributions define a .var property but not the standard .variance:

The canonical statistic across every other distribution (and the Distribution base class) is .variance. Because these classes only define .var, calling the standard .variance falls through to the base-class property, which raise NotImplementedError:

import numpyro.distributions as dist
d = dist.LeftTruncatedDistribution(dist.Normal(0, 1), low=0.0)
d.var       # -> works, returns the variance
d.variance  # -> NotImplementedError  (standard API is silently broken)

The .var bodies compute the truncated-Normal variance correctly — they're just exposed under a non-standard name, so the documented .variance API is broken for these three distributions.

Proposed fix

Rename varvariance on all three classes. This is safe and self-contained:

  • No caller in the codebase reads .var on these distributions (the only .var references — in diagnostics.py and test_distributions.py — are numpy/scipy .var() calls, unrelated).
  • Restores the standard .variance API.

Optionally add a test asserting .variance returns the value for these truncated distributions (the existing suite only exercised the wrongly-named .var indirectly, if at all).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions