Skip to content

truncnorm does not work if b < a in scipy.stats #9169

@chrisb83

Description

@chrisb83

truncnorm does not check that a < b. If b > a, one can produce rvs but the pdf and cdf do not work.
Should be easy to fix using _argcheck.

Reproducing code example:

from scipy import stats
import numpy as np

x = np.arange(1, 2, 0.1)
stats.truncnorm(2, 1).pdf(x) # all 0
stats.truncnorm(2, 1).cdf(1) # 1.0
stats.truncnorm(2, 1).cdf(0.999) # 0.0
stats.truncnorm(2, 1).rvs(size=5, random_state=123) 
# array([1.1880652 , 1.54116815, 1.61108676, 1.29490424, 1.17234318])

This does not make sense.

Scipy/Numpy/Python version information:

1.0.0 1.14.1 sys.version_info(major=3, minor=5, micro=4, releaselevel='final', serial=0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedgood first issueGood topic for first contributor pull requests, with a relatively straightforward solutionscipy.stats

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions