Repository: scipy/scipy
File: scipy/stats/tests/test_distributions.py (Python)

Code before:
        unfrozen = stats.levy_stable

        with levy_stable_lock:
            unfrozen.parameterization = "S0"
            frozen = stats.levy_stable(**shapes)
            unfrozen_a = unfrozen.rvs(**shapes, size=10, random_state=rng(329823498))
            frozen_a = frozen.rvs(size=10, random_state=rng(329823498))
            assert_equal(frozen_a, unfrozen_a)

            unfrozen.parameterization = "S1"
            frozen = stats.levy_stable(**shapes)
            unfrozen_b = unfrozen.rvs(**shapes, size=10, random_state=rng(329823498))
            frozen_b = frozen.rvs(size=10, random_state=rng(329823498))
            assert_equal(frozen_b, unfrozen_b)

    @pytest.mark.parametrize(
        "param, alpha, beta, xs, expected",
        [
            (
                0,
                1.6,
                1.0,
                [-15.0, -14.0, -13.0],
                [-187.1444263, -157.1411663, -130.3526688],
            ),
            (
                1,
                1.6,
                1.0,
                [-15.0, -14.0, -13.0],
                [-165.0203129, -137.3671717, -112.8223545],
            ),
            (
                0,
                1.4,
                -1.0,
                [13.0, 14.0, 15.0],
                [-367.1943293, -464.7049565, -579.4399286],
            ),
            (
                1,
                1.4,
                -1.0,
                [13.0, 14.0, 15.0],
                [-258.1216497, -334.6139857, -426.0724094],
            ),
        ],
    )
    def test_logpdf_tail(self, param, alpha, beta, xs, expected):
        # gh-20636
        # Expected values computed from Mathematica. Mathematica command is:

Review comment (bug):
```suggestion
    @pytest.mark.xfail_on_32bit("`bisect` fails to recognize valid bracket")
    def test_logpdf_tail(self, param, alpha, beta, xs, expected):
```

Code after:
        unfrozen = stats.levy_stable

        with levy_stable_lock:
            unfrozen.parameterization = "S0"
            frozen = stats.levy_stable(**shapes)
            unfrozen_a = unfrozen.rvs(**shapes, size=10, random_state=rng(329823498))
            frozen_a = frozen.rvs(size=10, random_state=rng(329823498))
            assert_equal(frozen_a, unfrozen_a)

            unfrozen.parameterization = "S1"
            frozen = stats.levy_stable(**shapes)
            unfrozen_b = unfrozen.rvs(**shapes, size=10, random_state=rng(329823498))
            frozen_b = frozen.rvs(size=10, random_state=rng(329823498))
            assert_equal(frozen_b, unfrozen_b)

    @pytest.mark.parametrize(
        "param, alpha, beta, xs, expected",
        [
            (0, 1.6, 1, [-15, -14, -13], [-187.1444263, -157.1411663, -130.3526688]),
            (1, 1.6, 1, [-15, -14, -13], [-165.0203129, -137.3671717, -112.8223545]),
            (0, 1.4, -1, [13, 14, 15], [-367.1943293, -464.7049565, -579.4399286]),
            (1, 1.4, -1, [13, 14, 15], [-258.1216497, -334.6139857, -426.0724094]),
        ],
    )
    @pytest.mark.xfail_on_32bit("`bisect` fails to recognize valid bracket")
    def test_logpdf_tail(self, param, alpha, beta, xs, expected):
        # gh-20636
        # Expected values computed from Mathematica. Mathematica command is:
        # Log[PDF[StableDistribution[0, 1.6, 1, 0, 1], -15.0]] // InputForm
        # Test levy_stable.logpdf accuracy in the tails when beta=1 or beta=-1
        # for both S0/S1 parameterizations.
        # Testing logpdf instead of pdf as more compact.
        stats.levy_stable.parameterization = f"S{param}"
        logpdfs = stats.levy_stable(alpha=alpha, beta=beta).logpdf(xs)
        assert_allclose(logpdfs, expected, rtol=1e-5)

class TestArrayArgument:  # test for ticket:992
    def setup_method(self):
        self.rng = np.random.default_rng(7556981556)

    def test_noexception(self):
        rvs = stats.norm.rvs(loc=(np.arange(5)), scale=np.ones(5),
                             size=(10, 5), random_state=self.rng)
        assert_equal(rvs.shape, (10, 5))


class TestDocstring:
    def test_docstrings(self):
        # See ticket #761
        if stats.rayleigh.__doc__ is not None:
            assert_("rayleigh" in stats.rayleigh.__doc__.lower())