Repository: scipy/scipy

Issue:
BUG: stats: Occasional failures of some tests of `levy_stable`
If I repeatedly run just the tests in `scipy/stats/tests/test_distributions.py` with the command

```
python3 dev.py test -m full -j 9 -t scipy.stats.tests.test_distributions
```

occasionally I get a batch of 5 or more failures of tests of the Levy stable distribution.  I might be able to run that command a dozen or more times and not get any failures, but inevitably I get a batch of failures like those shown below.

<details>
<summary>The full output for an example with 5 failures.</summary>

```
$ python3 dev.py test -m full -j 9 -t scipy.stats.tests.test_distributions
💻  ninja -C /home/warren/repos/git/forks/scipy/build
ninja: Entering directory `/home/warren/repos/git/forks/scipy/build'
[2/2] Generating scipy/generate-config with a custom command
Build OK
💻  meson install -C build --only-changed
Installing, see meson-install.log...
Installation OK
SciPy from development installed path at: /home/warren/repos/git/forks/scipy/build-install/lib/python3.10/site-packages
Running tests for scipy version:1.10.0.dev0+2244.033451e, installed at:/home/warren/repos/git/forks/scipy/build-install/lib/python3.10/site-packages/scipy
======================================================================== test session starts =========================================================================
platform linux -- Python 3.10.8, pytest-7.1.3, pluggy-1.0.0
rootdir: /home/warren/repos/git/forks/scipy, configfile: pytest.ini
plugins: forked-1.4.0, timeout-2.1.0, hypothesis-6.56.3, xdist-2.5.0, cov-4.0.0
gw0 [1558] / gw1 [1558] / gw2 [1558] / gw3 [1558] / gw4 [1558] / gw5 [1558] / gw6 [1558] / gw7 [1558] / gw8 [1558]
.............................................................................................................................................................. [ 10%]
.............................................................................................................................................................. [ 20%]
.............................................................................................................................................................. [ 30%]
.............................................................................................................................................................. [ 40%]
...............................................................................................................................s.....................s........ [ 50%]
.......................................................................................................s...................................................... [ 60%]
.............................................................................................................................................................. [ 70%]
.............................................................................................................................................................. [ 81%]
.....................xxxx....x.x.......x........xx...x.x.x.xxxxxxx................x........x...................................x.............................. [ 91%]
....................s..................s...................xxxx....x.....s..........xxx....FFFsFFs...............s.....................x                       [100%]
============================================================================== FAILURES ==============================================================================
_________________________________________________________________ TestLevyStable.test_fit_loc_extrap _________________________________________________________________
[gw2] linux -- Python 3.10.8 /home/warren/py3.10.8/bin/python3
scipy/stats/tests/test_distributions.py:3747: in test_fit_loc_extrap
    assert loc1 < min(x), f"Expected loc < {min(x)}, got {loc1}"
E   AssertionError: Expected loc < 1, got 4.766064688276174
E   assert 4.766064688276174 < 1
E    +  where 1 = min([1, 1, 3, 3, 10, 10, ...])
        alpha1     = 0.9820903277378099
        beta1      = 1.0
        loc1       = 4.766064688276174
        scale1     = 8.876924271494387
        self       = <scipy.stats.tests.test_distributions.TestLevyStable object at 0x7f56864f7e20>
        x          = [1, 1, 3, 3, 10, 10, ...]
_____________________________________________ TestLevyStable.test_pdf_nolan_samples[pct_range0-alpha_range0-beta_range0] _____________________________________________
[gw2] linux -- Python 3.10.8 /home/warren/py3.10.8/bin/python3
scipy/stats/tests/test_distributions.py:3957: in test_pdf_nolan_samples
    assert_allclose(
E   AssertionError: 
E   Not equal to tolerance rtol=1e-07, atol=0
E   pdf test 0 failed with method 'dni' [platform: Linux/x86_64/x86_64]
E   ('x', 'p', 'alpha', 'beta', 'pct', 'calc', 'abserr', 'relerr')
E   [(5.01135328, 0.00650864, 0.1, 0.8, 0.5, 0.00634502, 0.00016362, 0.02513946)]
E   Mismatched elements: 1 / 8 (12.5%)
E   Max absolute difference: 0.00016362
E   Max relative difference: 0.02513946
        alpha_range = [0.1, 1, 2]
        beta_range = [-1, 0, 0.8]
        data       = rec.array([(-5.54809272e+19, 1.79355106e-23, 0.1, -1., 0.01),
           (-1.93540945e-07, 2.45039317e+04, 0.1, -1., 0...-02, 2. ,  1., 0.95)],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        default_method = 'dni'
        failures   = rec.array([(5.01135328, 0.00650864, 0.1, 0.8, 0.5, 0.00634502, 0.00016362, 0.02513946)],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8'), ('calc', '<f8'), ('abserr', '<f8'), ('relerr', '<f8')])
        filter_func = <function TestLevyStable.test_pdf_nolan_samples.<locals>.<lambda> at 0x7f56862eb520>
        is_linux_32 = False
        ix         = 0
        nolan_pdf_sample_data = rec.array([(-5.54809272e+19, 1.79355106e-23, 0.1, -1., 0.01),
           (-1.93540945e-07, 2.45039317e+04, 0.1, -1., 0...-02, 2. ,  1., 0.95)],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        p          = array([1.55484963e-04, 5.38427032e-02, 3.14055925e-04, 3.14055925e-04,
       1.71559370e-03, 1.72948846e-04, 6.34501799e-03, 2.26119951e-01])
        pct_range  = [0.01, 0.5, 0.99]
        platform_desc = 'Linux/x86_64/x86_64'
        rtol       = 1e-07
        self       = <scipy.stats.tests.test_distributions.TestLevyStable object at 0x7f5686538100>
        subdata    = rec.array([(-66.02051287, 1.55484963e-04, 1. , -1. , 0.01),
           (  1.62750611, 5.38427032e-02, 1. , -1. , 0.99)...01, 1. ,  0.8, 0.5 )],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        subdata2   = rec.array([(-66.02051287, 1.55484963e-04, 1. , -1. , 0.01, 1.55484963e-04, 9.08019319e-18, 5.83991727e-14),
          ...'p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8'), ('calc', '<f8'), ('abserr', '<f8'), ('relerr', '<f8')])
        sup        = <numpy.testing._private.utils.suppress_warnings object at 0x7f5683f04790>
        tests      = [['dni', 1e-07, <function TestLevyStable.test_pdf_nolan_samples.<locals>.<lambda> at 0x7f56862eb520>], ['piecewise', 1...2e9d80>], ['fft-simpson', 1e-06, <function TestLevyStable.test_pdf_nolan_samples.<locals>.<lambda> at 0x7f56862ea320>]]
        uname      = uname_result(system='Linux', node='pop-os', release='6.0.6-76060006-generic', version='#202210290932~1667401208~22.04~d2df702 SMP PREEMPT_DYNAMIC Wed N', machine='x86_64')
_____________________________________________ TestLevyStable.test_pdf_nolan_samples[pct_range1-alpha_range1-beta_range1] _____________________________________________
[gw2] linux -- Python 3.10.8 /home/warren/py3.10.8/bin/python3
scipy/stats/tests/test_distributions.py:3957: in test_pdf_nolan_samples
    assert_allclose(
E   AssertionError: 
E   Not equal to tolerance rtol=1e-07, atol=0
E   pdf test 0 failed with method 'dni' [platform: Linux/x86_64/x86_64]
E   ('x', 'p', 'alpha', 'beta', 'pct', 'calc', 'abserr', 'relerr')
E   [(-5.73914563e+03, 8.70705538e-07, 0.5, -0.9, 0.01, 8.70500847e-07, 2.04690415e-10, 2.35085693e-04)
E    ( 1.02062204e+01, 3.88044901e-04, 0.5, -0.9, 0.99, 4.36597334e-04, 4.85524338e-05, 1.25120659e-01)
E    (-3.55694820e+03, 1.40093318e-06, 0.5, -0.5, 0.01, 1.40063851e-06, 2.94668580e-10, 2.10337355e-04)
E    ( 3.74198714e+02, 1.29550388e-05, 0.5, -0.5, 0.99, 1.29805152e-05, 2.54763738e-08, 1.96652239e-03)
E    (-7.51006192e+02, 6.53273786e-06, 0.5,  0.3, 0.01, 6.53660490e-06, 3.86703928e-09, 5.91947720e-04)
E    ( 2.66065606e+03, 1.86899439e-06, 0.5,  0.3, 0.99, 1.86867949e-06, 3.14905683e-10, 1.68489368e-04)
E    (-2.34496878e+02, 2.04531443e-05, 0.5,  0.6, 0.01, 2.05297295e-05, 7.65851838e-08, 3.74442103e-03)
E    ( 4.05379591e+03, 1.23026028e-06, 0.5,  0.6, 0.99, 1.22998767e-06, 2.72614497e-10, 2.21590912e-04)
E    (-1.14074881e+01, 2.96494615e-03, 0.1, -0.9, 0.5 , 2.92740714e-03, 3.75390072e-05, 1.26609406e-02)
E    (-1.86316800e+00, 1.10890594e-01, 0.5, -0.9, 0.5 , 6.69861409e-02, 4.39044527e-02, 3.95925852e-01)
E    (-2.36071963e-01, 1.16805188e-01, 0.1, -0.5, 0.5 , 8.76627331e-02, 2.91424551e-02, 2.49496238e-01)
E    (-7.79429212e-01, 2.06751537e-01, 0.5, -0.5, 0.5 , 1.20849167e-01, 8.59023702e-02, 4.15486005e-01)
E    ( 1.28434280e-02, 1.71575886e+00, 0.1,  0.3, 0.5 , 3.85739851e-01, 1.33001901e+00, 7.75178284e-01)
E    ( 3.91696636e-01, 3.11394050e-01, 0.5,  0.3, 0.5 , 1.87624428e-01, 1.23769622e-01, 3.97469450e-01)
E    ( 7.39504876e-01, 3.99739613e-02, 0.1,  0.6, 0.5 , 3.54090050e-02, 4.56495623e-03, 1.14198245e-01)
E    ( 1.01189642e+00, 1.73416845e-01, 0.5,  0.6, 0.5 , 1.01634009e-01, 7.17828354e-02, 4.13932312e-01)
E    (-2.28310117e+02, 1.09067873e-04, 0.5, -0.9, 0.05, 1.08428081e-04, 6.39792755e-07, 5.86600559e-03)
E    (-1.32884623e-01, 3.02393754e-01, 0.5, -0.9, 0.95, 2.18311499e-01, 8.40822543e-02, 2.78055526e-01)
E    (-1.38300000e+02, 1.77491054e-04, 0.5, -0.5, 0.05, 1.76544856e-04, 9.46198221e-07, 5.33096287e-03)
E    ( 1.13299218e+01, 1.84840548e-03, 0.5, -0.5, 0.95, 1.96266669e-03, 1.14261208e-04, 6.18160947e-02)
E    (-2.55162860e+01, 8.83502673e-04, 0.5,  0.3, 0.05, 8.98237688e-04, 1.47350151e-05, 1.66779519e-02)
E    ( 1.01699326e+02, 2.38795527e-04, 0.5,  0.3, 0.95, 2.37763387e-04, 1.03214023e-06, 4.32227622e-03)
E    (-6.33940967e+00, 3.06979486e-03, 0.5,  0.6, 0.05, 3.47962555e-03, 4.09830687e-04, 1.33504259e-01)
E    ( 1.58701442e+02, 1.55339758e-04, 0.5,  0.6, 0.95, 1.54471469e-04, 8.68289123e-07, 5.58961294e-03)
E    ( 1.50718249e-01, 2.47122230e-01, 0.5,  1. , 0.01, 2.09291088e-01, 3.78311414e-02, 1.53086760e-01)
E    ( 6.36586439e+03, 7.85398163e-07, 0.5,  1. , 0.99, 7.85213144e-07, 1.85018753e-10, 2.35573193e-04)
E    ( 2.42640781e+01, 1.43715876e-03, 0.1,  1. , 0.5 , 1.42754615e-03, 9.61260593e-06, 6.68861800e-03)
E    ( 2.19810934e+00, 9.75097268e-02, 0.5,  1. , 0.5 , 5.96583826e-02, 3.78513442e-02, 3.88180189e-01)
E    ( 2.60317772e-01, 4.40039999e-01, 0.5,  1. , 0.05, 1.89624456e-01, 2.50415543e-01, 5.69074501e-01)
E    ( 2.54314445e+02, 9.81747198e-05, 0.5,  1. , 0.95, 9.75992494e-05, 5.75470388e-07, 5.86169626e-03)]
E   Mismatched elements: 30 / 62 (48.4%)
E   Max absolute difference: 1.33001901
E   Max relative difference: 0.77517828
        alpha_range = [0.1, 0.5, 1, 1.5, 2]
        beta_range = [-0.9, -0.5, 0, 0.3, 0.6, 1]
        data       = rec.array([(-5.54809272e+19, 1.79355106e-23, 0.1, -1., 0.01),
           (-1.93540945e-07, 2.45039317e+04, 0.1, -1., 0...-02, 2. ,  1., 0.95)],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        default_method = 'dni'
        failures   = rec.array([(-5.73914563e+03, 8.70705538e-07, 0.5, -0.9, 0.01, 8.70500847e-07, 2.04690415e-10, 2.35085693e-04),
       ...'p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8'), ('calc', '<f8'), ('abserr', '<f8'), ('relerr', '<f8')])
        filter_func = <function TestLevyStable.test_pdf_nolan_samples.<locals>.<lambda> at 0x7f56862e9ea0>
        is_linux_32 = False
        ix         = 0
        nolan_pdf_sample_data = rec.array([(-5.54809272e+19, 1.79355106e-23, 0.1, -1., 0.01),
           (-1.93540945e-07, 2.45039317e+04, 0.1, -1., 0...-02, 2. ,  1., 0.95)],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        p          = array([8.70500847e-07, 4.36597334e-04, 1.63752569e-04, 3.98744049e-03,
       1.40063851e-06, 1.29805152e-05, 2.079916...615e-03,
       5.96583826e-02, 2.04481748e-01, 1.89624456e-01, 9.75992494e-05,
       1.58266247e-01, 3.71974588e-03])
        pct_range  = [0.01, 0.05, 0.5, 0.95, 0.99]
        platform_desc = 'Linux/x86_64/x86_64'
        rtol       = 1e-07
        self       = <scipy.stats.tests.test_distributions.TestLevyStable object at 0x7f5686538190>
        subdata    = rec.array([(-5.73914563e+03, 8.70705538e-07, 0.5, -0.9, 0.01),
           ( 1.02062204e+01, 3.88044901e-04, 0.5, -0.9,...03, 1. ,  1. , 0.95)],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        subdata2   = rec.array([(-5.73914563e+03, 8.70705538e-07, 0.5, -0.9, 0.01, 8.70500847e-07, 2.04690415e-10, 2.35085693e-04),
       ...'p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8'), ('calc', '<f8'), ('abserr', '<f8'), ('relerr', '<f8')])
        sup        = <numpy.testing._private.utils.suppress_warnings object at 0x7f568413a5c0>
        tests      = [['dni', 1e-07, <function TestLevyStable.test_pdf_nolan_samples.<locals>.<lambda> at 0x7f56862e9ea0>], ['piecewise', 1...1c68c0>], ['fft-simpson', 1e-06, <function TestLevyStable.test_pdf_nolan_samples.<locals>.<lambda> at 0x7f56861c6950>]]
        uname      = uname_result(system='Linux', node='pop-os', release='6.0.6-76060006-generic', version='#202210290932~1667401208~22.04~d2df702 SMP PREEMPT_DYNAMIC Wed N', machine='x86_64')
_____________________________________________ TestLevyStable.test_cdf_nolan_samples[pct_range0-alpha_range0-beta_range0] _____________________________________________
[gw2] linux -- Python 3.10.8 /home/warren/py3.10.8/bin/python3
scipy/stats/tests/test_distributions.py:4103: in test_cdf_nolan_samples
    assert_allclose(
E   AssertionError: 
E   Not equal to tolerance rtol=1e-12, atol=0
E   cdf test 0 failed with method 'piecewise'
E   ('x', 'p', 'alpha', 'beta', 'pct', 'calc', 'abserr', 'relerr')
E   [(-1.93540945e-07, 0.99, 0.1, -1. , 0.99, 0.68367464, 3.06325363e-01, 3.09419559e-01)
E    (-3.40893481e+09, 0.01, 0.1,  0.8, 0.01, 0.01      , 3.51923352e-14, 3.51923352e-12)
E    ( 5.01135328e+00, 0.5 , 0.1,  0.8, 0.5 , 0.50081424, 8.14241096e-04, 1.62848219e-03)]
E   Mismatched elements: 3 / 25 (12%)
E   Max absolute difference: 0.30632536
E   Max relative difference: 0.30941956
        alpha_range = [0.1, 1, 2]
        beta_range = [-1, 0, 0.8]
        data       = rec.array([(-5.54809272e+19, 0.01, 0.1, -1., 0.01),
           (-1.93540945e-07, 0.99, 0.1, -1., 0.99),
           (-5....95, 2. ,  1., 0.95)],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        default_method = 'piecewise'
        failures   = rec.array([(-1.93540945e-07, 0.99, 0.1, -1. , 0.99, 0.68367464, 3.06325363e-01, 3.09419559e-01),
           (-3.408934...'p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8'), ('calc', '<f8'), ('abserr', '<f8'), ('relerr', '<f8')])
        filter_func = <function TestLevyStable.test_cdf_nolan_samples.<locals>.<lambda> at 0x7f56862eb010>
        ix         = 0
        nolan_cdf_sample_data = rec.array([(-5.54809272e+19, 0.01, 0.1, -1., 0.01),
           (-1.93540945e-07, 0.99, 0.1, -1., 0.99),
           (-5....95, 2. ,  1., 0.95)],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        p          = array([0.01      , 0.68367464, 0.01      , 0.99      , 0.01      ,
       0.99      , 0.01      , 0.99      , 0.01    ...  , 0.01      , 0.99      , 0.5       , 0.5       ,
       0.50081424, 0.5       , 0.5       , 0.5       , 0.5       ])
        pct_range  = [0.01, 0.5, 0.99]
        rtol       = 1e-12
        self       = <scipy.stats.tests.test_distributions.TestLevyStable object at 0x7f5686538490>
        subdata    = rec.array([(-5.54809272e+19, 0.01, 0.1, -1. , 0.01),
           (-1.93540945e-07, 0.99, 0.1, -1. , 0.99),
           (...5 , 2. ,  0.8, 0.5 )],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        subdata2   = rec.array([(-5.54809272e+19, 0.01, 0.1, -1. , 0.01, 0.01      , 8.67361738e-18, 8.67361738e-16),
           (-1.935409...'p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8'), ('calc', '<f8'), ('abserr', '<f8'), ('relerr', '<f8')])
        sup        = <numpy.testing._private.utils.suppress_warnings object at 0x7f568411b820>
        tests      = [['piecewise', 1e-12, <function TestLevyStable.test_cdf_nolan_samples.<locals>.<lambda> at 0x7f56862eb010>], ['piecewi...62ea050>], ['fft-simpson', 0.01, <function TestLevyStable.test_cdf_nolan_samples.<locals>.<lambda> at 0x7f56862e9bd0>]]
_____________________________________________ TestLevyStable.test_cdf_nolan_samples[pct_range1-alpha_range1-beta_range1] _____________________________________________
[gw2] linux -- Python 3.10.8 /home/warren/py3.10.8/bin/python3
scipy/stats/tests/test_distributions.py:4103: in test_cdf_nolan_samples
    assert_allclose(
E   AssertionError: 
E   Not equal to tolerance rtol=1e-12, atol=0
E   cdf test 0 failed with method 'piecewise'
E   ('x', 'p', 'alpha', 'beta', 'pct', 'calc', 'abserr', 'relerr')
E   [( 1.84116513e+06, 0.99, 0.1, -0.9, 0.99, 9.90000000e-01, 6.88625823e-11, 6.95581639e-11)
E    (-5.73914563e+03, 0.01, 0.5, -0.9, 0.01, 9.99921646e-03, 7.83542867e-07, 7.83542867e-05)
E    ( 1.02062204e+01, 0.99, 0.5, -0.9, 0.99, 9.89629649e-01, 3.70350679e-04, 3.74091595e-04)
E    (-3.55694820e+03, 0.01, 0.5, -0.5, 0.01, 9.99929961e-03, 7.00392919e-07, 7.00392919e-05)
E    ( 3.74198714e+02, 0.99, 0.5, -0.5, 0.99, 9.89993516e-01, 6.48388501e-06, 6.54937880e-06)
E    (-7.51006192e+02, 0.01, 0.5,  0.3, 0.01, 1.00019604e-02, 1.96040132e-06, 1.96040132e-04)
E    ( 2.66065606e+03, 0.99, 0.5,  0.3, 0.99, 9.90000561e-01, 5.60651080e-07, 5.66314222e-07)
E    (-2.34496878e+02, 0.01, 0.5,  0.6, 0.01, 1.00122948e-02, 1.22948382e-05, 1.22948382e-03)
E    ( 4.05379591e+03, 0.99, 0.5,  0.6, 0.99, 9.90000738e-01, 7.38074379e-07, 7.45529676e-07)
E    (-1.12939329e+01, 0.01, 1.5, -0.9, 0.01, 1.13241001e-02, 1.32410012e-03, 1.32410012e-01)
E    ( 3.56244482e+00, 0.99, 1.5, -0.9, 0.99, 9.96483292e-01, 6.48329226e-03, 6.54878006e-03)
E    (-9.79158434e+00, 0.01, 1.5, -0.5, 0.01, 1.08365420e-02, 8.36541973e-04, 8.36541973e-02)
E    ( 5.38825761e+00, 0.99, 1.5, -0.5, 0.99, 9.91530425e-01, 1.53042468e-03, 1.54588351e-03)
E    (-6.37130761e+00, 0.01, 1.5,  0.3, 0.01, 9.23784216e-03, 7.62157839e-04, 7.62157839e-02)
E    ( 8.99696608e+00, 0.99, 1.5,  0.3, 0.99, 9.89457301e-01, 5.42699189e-04, 5.48180999e-04)
E    (-4.87484356e+00, 0.01, 1.5,  0.6, 0.01, 7.91794269e-03, 2.08205731e-03, 2.08205731e-01)
E    ( 1.01772512e+01, 0.99, 1.5,  0.6, 0.99, 9.89030835e-01, 9.69164628e-04, 9.78954170e-04)
E    (-1.14074881e+01, 0.5 , 0.1, -0.9, 0.5 , 4.99580045e-01, 4.19954507e-04, 8.39909013e-04)
E    (-1.86316800e+00, 0.5 , 0.5, -0.9, 0.5 , 4.22688541e-01, 7.73114592e-02, 1.54622918e-01)
E    (-2.36071963e-01, 0.5 , 0.1, -0.5, 0.5 , 4.92013788e-01, 7.98621152e-03, 1.59724230e-02)
E    (-7.79429212e-01, 0.5 , 0.5, -0.5, 0.5 , 4.21297361e-01, 7.87026387e-02, 1.57405277e-01)
E    ( 1.28434280e-02, 0.5 , 0.1,  0.3, 0.5 , 5.35150954e-01, 3.51509539e-02, 7.03019078e-02)
E    ( 3.91696636e-01, 0.5 , 0.5,  0.3, 0.5 , 5.72244452e-01, 7.22444524e-02, 1.44488905e-01)
E    ( 7.39504876e-01, 0.5 , 0.1,  0.6, 0.5 , 5.03573139e-01, 3.57313926e-03, 7.14627852e-03)
E    ( 1.01189642e+00, 0.5 , 0.5,  0.6, 0.5 , 5.79333438e-01, 7.93334377e-02, 1.58666875e-01)
E    ( 6.48282753e-01, 0.5 , 1.5, -0.9, 0.5 , 7.46673514e-01, 2.46673514e-01, 4.93347028e-01)
E    ( 3.66146958e-01, 0.5 , 1.5, -0.5, 0.5 , 6.41472367e-01, 1.41472367e-01, 2.82944734e-01)
E    (-2.20855522e-01, 0.5 , 1.5,  0.3, 0.5 , 4.14281678e-01, 8.57183216e-02, 1.71436643e-01)
E    (-4.37852518e-01, 0.5 , 1.5,  0.6, 0.5 , 3.31338228e-01, 1.68661772e-01, 3.37323545e-01)
E    (-2.21525105e-09, 0.95, 0.1, -0.9, 0.95, 6.52750167e-01, 2.97249833e-01, 3.12894561e-01)
E    (-2.28310117e+02, 0.05, 0.5, -0.9, 0.05, 4.99021273e-02, 9.78727086e-05, 1.95745417e-03)
E    (-1.32884623e-01, 0.95, 0.5, -0.9, 0.95, 6.28585228e-01, 3.21414772e-01, 3.38331339e-01)
E    ( 1.86339703e+06, 0.95, 0.1, -0.5, 0.95, 9.50000000e-01, 1.89243510e-10, 1.99203694e-10)
E    (-1.38300000e+02, 0.05, 0.5, -0.5, 0.05, 4.99114914e-02, 8.85086256e-05, 1.77017251e-03)
E    ( 1.13299218e+01, 0.95, 0.5, -0.5, 0.95, 9.49047719e-01, 9.52280766e-04, 1.00240081e-03)
E    (-7.61040064e+07, 0.05, 0.1,  0.3, 0.05, 5.00000000e-02, 2.88462310e-12, 5.76924619e-11)
E    (-2.55162860e+01, 0.05, 0.5,  0.3, 0.05, 5.02672508e-02, 2.67250760e-04, 5.34501520e-03)
E    ( 1.01699326e+02, 0.95, 0.5,  0.3, 0.95, 9.50071484e-01, 7.14836502e-05, 7.52459475e-05)
E    (-1.45375674e+05, 0.05, 0.1,  0.6, 0.05, 5.00000028e-02, 2.81138305e-09, 5.62276610e-08)
E    (-6.33940967e+00, 0.05, 0.5,  0.6, 0.05, 5.19604004e-02, 1.96040038e-03, 3.92080077e-02)
E    ( 1.58701442e+02, 0.95, 0.5,  0.6, 0.95, 9.50092943e-01, 9.29429619e-05, 9.78346967e-05)
E    (-3.74651613e+00, 0.05, 1.5, -0.9, 0.05, 7.15212648e-02, 2.15212648e-02, 4.30425296e-01)
E    ( 2.69618249e+00, 0.95, 1.5, -0.9, 0.95, 9.90547342e-01, 4.05473425e-02, 4.26814131e-02)
E    (-3.43365879e+00, 0.05, 1.5, -0.5, 0.05, 6.29826955e-02, 1.29826955e-02, 2.59653909e-01)
E    ( 2.75418584e+00, 0.95, 1.5, -0.5, 0.95, 9.68714363e-01, 1.87143634e-02, 1.96993299e-02)
E    (-2.85282703e+00, 0.05, 1.5,  0.3, 0.05, 3.98155608e-02, 1.01844392e-02, 2.03688785e-01)
E    ( 3.27794499e+00, 0.95, 1.5,  0.3, 0.95, 9.41802217e-01, 8.19778330e-03, 8.62924558e-03)
E    (-2.72080458e+00, 0.05, 1.5,  0.6, 0.05, 2.63752130e-02, 2.36247870e-02, 4.72495740e-01)
E    ( 3.51196025e+00, 0.95, 1.5,  0.6, 0.95, 9.34771644e-01, 1.52283560e-02, 1.60298484e-02)
E    ( 1.93540944e-07, 0.01, 0.1,  1. , 0.01, 3.16325363e-01, 3.06325363e-01, 3.06325363e+01)
E    ( 1.50718249e-01, 0.01, 0.5,  1. , 0.01, 3.51226076e-01, 3.41226076e-01, 3.41226076e+01)
E    ( 6.36586439e+03, 0.99, 0.5,  1. , 0.99, 9.90000785e-01, 7.85305647e-07, 7.93238028e-07)
E    (-3.37113345e+00, 0.01, 1.5,  1. , 0.01, 2.52408446e-04, 9.74759155e-03, 9.74759155e-01)
E    ( 1.16541344e+01, 0.99, 1.5,  1. , 0.99, 9.88569129e-01, 1.43087144e-03, 1.44532469e-03)
E    ( 2.42640781e+01, 0.5 , 0.1,  1. , 0.5 , 5.00226861e-01, 2.26860670e-04, 4.53721341e-04)
E    ( 2.19810934e+00, 0.5 , 0.5,  1. , 0.5 , 5.76037373e-01, 7.60373730e-02, 1.52074746e-01)
E    (-7.16710685e-01, 0.5 , 1.5,  1. , 0.5 , 2.28671480e-01, 2.71328520e-01, 5.42657039e-01)
E    ( 1.28067044e-05, 0.05, 0.1,  1. , 0.05, 3.16328291e-01, 2.66328291e-01, 5.32656582e+00)
E    ( 2.60317772e-01, 0.05, 0.5,  1. , 0.05, 3.73058749e-01, 3.23058749e-01, 6.46117499e+00)
E    ( 2.54314445e+02, 0.95, 0.5,  1. , 0.95, 9.50097887e-01, 9.78865148e-05, 1.03038437e-04)
E    (-2.71174467e+00, 0.05, 1.5,  1. , 0.05, 3.43436513e-03, 4.65656349e-02, 9.31312697e-01)
E    ( 3.82423597e+00, 0.95, 1.5,  1. , 0.95, 9.26500548e-01, 2.34994520e-02, 2.47362652e-02)]
E   Mismatched elements: 62 / 149 (41.6%)
E   Max absolute difference: 0.34122608
E   Max relative difference: 34.12260761
        alpha_range = [0.1, 0.5, 1, 1.5, 2]
        beta_range = [-0.9, -0.5, 0, 0.3, 0.6, 1]
        data       = rec.array([(-5.54809272e+19, 0.01, 0.1, -1., 0.01),
           (-1.93540945e-07, 0.99, 0.1, -1., 0.99),
           (-5....95, 2. ,  1., 0.95)],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        default_method = 'piecewise'
        failures   = rec.array([( 1.84116513e+06, 0.99, 0.1, -0.9, 0.99, 9.90000000e-01, 6.88625823e-11, 6.95581639e-11),
           (-5.73...'p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8'), ('calc', '<f8'), ('abserr', '<f8'), ('relerr', '<f8')])
        filter_func = <function TestLevyStable.test_cdf_nolan_samples.<locals>.<lambda> at 0x7f56862eadd0>
        ix         = 0
        nolan_cdf_sample_data = rec.array([(-5.54809272e+19, 0.01, 0.1, -1., 0.01),
           (-1.93540945e-07, 0.99, 0.1, -1., 0.99),
           (-5....95, 2. ,  1., 0.95)],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        p          = array([1.00000000e-02, 9.90000000e-01, 9.99921646e-03, 9.89629649e-01,
       1.00000000e-02, 9.90000000e-01, 1.000000...887e-01, 5.00000000e-02,
       9.50000000e-01, 3.43436513e-03, 9.26500548e-01, 5.00000000e-02,
       9.50000000e-01])
        pct_range  = [0.01, 0.05, 0.5, 0.95, 0.99]
        rtol       = 1e-12
        self       = <scipy.stats.tests.test_distributions.TestLevyStable object at 0x7f5686538520>
        subdata    = rec.array([(-3.31276902e+19, 0.01, 0.1, -0.9, 0.01),
           ( 1.84116513e+06, 0.99, 0.1, -0.9, 0.99),
           (...95, 2. ,  1. , 0.95)],
          dtype=[('x', '<f8'), ('p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8')])
        subdata2   = rec.array([(-3.31276902e+19, 0.01, 0.1, -0.9, 0.01, 1.00000000e-02, 4.35415592e-16, 4.35415592e-14),
           ( 1.84...'p', '<f8'), ('alpha', '<f8'), ('beta', '<f8'), ('pct', '<f8'), ('calc', '<f8'), ('abserr', '<f8'), ('relerr', '<f8')])
        sup        = <numpy.testing._private.utils.suppress_warnings object at 0x7f5683f178b0>
        tests      = [['piecewise', 1e-12, <function TestLevyStable.test_cdf_nolan_samples.<locals>.<lambda> at 0x7f56862eadd0>], ['piecewi...61c6830>], ['fft-simpson', 0.01, <function TestLevyStable.test_cdf_nolan_samples.<locals>.<lambda> at 0x7f56861c67a0>]]
====================================================================== short test summary info =======================================================================
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_fit_loc_extrap - AssertionError: Expected loc < 1, got 4.766064688276174
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_pdf_nolan_samples[pct_range0-alpha_range0-beta_range0] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_pdf_nolan_samples[pct_range1-alpha_range1-beta_range1] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_cdf_nolan_samples[pct_range0-alpha_range0-beta_range0] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_cdf_nolan_samples[pct_range1-alpha_range1-beta_range1] - AssertionError: 
======================================================= 5 failed, 1513 passed, 9 skipped, 31 xfailed in 10.98s =======================================================

```

</details>

<details>
<summary>The summary output for another example, with 11 failures.</summary>

```
====================================================================== short test summary info =======================================================================
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_distribution_outside_support[cdf-1.0-points0-0.0-0.5] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_distribution_outside_support[cdf-1.0-points0-0.0-0.75] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_distribution_outside_support[pdf-1.0-points1-0.0-0.25] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_distribution_outside_support[pdf-1.0-points1-0.0-0.5] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_distribution_outside_support[pdf-1.0-points1-0.0-0.75] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_distribution_outside_support[cdf--1.0-points2-1.0-0.25] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_distribution_outside_support[cdf--1.0-points2-1.0-0.5] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_distribution_outside_support[cdf--1.0-points2-1.0-0.75] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_distribution_outside_support[pdf--1.0-points3-0.0-0.25] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_distribution_outside_support[pdf--1.0-points3-0.0-0.5] - AssertionError: 
FAILED scipy/stats/tests/test_distributions.py::TestLevyStable::test_distribution_outside_support[pdf--1.0-points3-0.0-0.75] - AssertionError: 
====================================================== 11 failed, 1507 passed, 9 skipped, 31 xfailed in 10.76s =======================================================

```

</details>



Discussion:
I get failures much more reliably if I run only the tests in the class `TestLevyStable`:

```
python3 dev.py test -m full -j 9 -t scipy.stats.tests.test_distributions::TestLevyStable
```

On my Linux machine, that produces at least one failure every time I run it.  I still get failures if I use `-j 4`, but for 2 or 3 workers, I don't observe any failures (so far).

Resolving patch:
diff --git a/scipy/stats/_levy_stable/__init__.py b/scipy/stats/_levy_stable/__init__.py
--- a/scipy/stats/_levy_stable/__init__.py
+++ b/scipy/stats/_levy_stable/__init__.py
@@ -128,6 +128,25 @@ def integrand2(t):
 )
 
 
+def _nolan_round_x_near_zeta(x0, alpha, zeta, x_tol_near_zeta):
+    """Round x close to zeta for Nolan's method in [NO]."""
+    #   "8. When |x0-beta*tan(pi*alpha/2)| is small, the
+    #   computations of the density and cumulative have numerical problems.
+    #   The program works around this by setting
+    #   z = beta*tan(pi*alpha/2) when
+    #   |z-beta*tan(pi*alpha/2)| < tol(5)*alpha**(1/alpha).
+    #   (The bound on the right is ad hoc, to get reasonable behavior
+    #   when alpha is small)."
+    # where tol(5) = 0.5e-2 by default.
+    #
+    # We seem to have partially addressed this through re-expression of
+    # g(theta) here, but it still needs to be used in some extreme cases.
+    # Perhaps tol(5) = 0.5e-2 could be reduced for our implementation.
+    if np.abs(x0 - zeta) < x_tol_near_zeta * alpha ** (1 / alpha):
+        x0 = zeta
+    return x0
+
+
 def _nolan_round_difficult_input(
     x0, alpha, beta, zeta, x_tol_near_zeta, alpha_tol_near_one
 ):
@@ -145,21 +164,7 @@ def _nolan_round_difficult_input(
     #   problems.  The current version sets beta=0."
     # We seem to have addressed this through re-expression of g(theta) here
 
-    #   "8. When |x0-beta*tan(pi*alpha/2)| is small, the
-    #   computations of the density and cumulative have numerical problems.
-    #   The program works around this by setting
-    #   z = beta*tan(pi*alpha/2) when
-    #   |z-beta*tan(pi*alpha/2)| < tol(5)*alpha**(1/alpha).
-    #   (The bound on the right is ad hoc, to get reasonable behavior
-    #   when alpha is small)."
-    # where tol(5) = 0.5e-2 by default.
-    #
-    # We seem to have partially addressed this through re-expression of
-    # g(theta) here, but it still needs to be used in some extreme cases.
-    # Perhaps tol(5) = 0.5e-2 could be reduced for our implementation.
-    if np.abs(x0 - zeta) < x_tol_near_zeta * alpha ** (1 / alpha):
-        x0 = zeta
-
+    x0 = _nolan_round_x_near_zeta(x0, alpha, zeta, x_tol_near_zeta)
     return x0, alpha, beta
 
 
@@ -211,11 +216,11 @@ def _pdf_single_value_piecewise_Z0(x0, alpha, beta, **kwds):
         return 1 / (1 + x0 ** 2) / np.pi
 
     return _pdf_single_value_piecewise_post_rounding_Z0(
-        x0, alpha, beta, quad_eps
+        x0, alpha, beta, quad_eps, x_tol_near_zeta
     )
 
 
-def _pdf_single_value_piecewise_post_rounding_Z0(x0, alpha, beta, quad_eps):
+def _pdf_single_value_piecewise_post_rounding_Z0(x0, alpha, beta, quad_eps, x_tol_near_zeta):
     """Calculate pdf using Nolan's methods as detailed in [NO].
     """
 
@@ -225,6 +230,10 @@ def _pdf_single_value_piecewise_post_rounding_Z0(x0, alpha, beta, quad_eps):
     c2 = _nolan.c2
     g = _nolan.g
 
+    # round x0 to zeta again if needed. zeta was recomputed and may have
+    # changed due to floating point differences.
+    # See https://github.com/scipy/scipy/pull/18133
+    x0 = _nolan_round_x_near_zeta(x0, alpha, zeta, x_tol_near_zeta)
     # handle Nolan's initial case logic
     if x0 == zeta:
         return (
@@ -235,7 +244,7 @@ def _pdf_single_value_piecewise_post_rounding_Z0(x0, alpha, beta, quad_eps):
         )
     elif x0 < zeta:
         return _pdf_single_value_piecewise_post_rounding_Z0(
-            -x0, alpha, -beta, quad_eps
+            -x0, alpha, -beta, quad_eps, x_tol_near_zeta
         )
 
     # following Nolan, we may now assume
@@ -328,11 +337,11 @@ def _cdf_single_value_piecewise_Z0(x0, alpha, beta, **kwds):
         return 0.5 + np.arctan(x0) / np.pi
 
     return _cdf_single_value_piecewise_post_rounding_Z0(
-        x0, alpha, beta, quad_eps
+        x0, alpha, beta, quad_eps, x_tol_near_zeta
     )
 
 
-def _cdf_single_value_piecewise_post_rounding_Z0(x0, alpha, beta, quad_eps):
+def _cdf_single_value_piecewise_post_rounding_Z0(x0, alpha, beta, quad_eps, x_tol_near_zeta):
     """Calculate cdf using Nolan's methods as detailed in [NO].
     """
     _nolan = Nolan(alpha, beta, x0)
@@ -342,7 +351,10 @@ def _cdf_single_value_piecewise_post_rounding_Z0(x0, alpha, beta, quad_eps):
     # c2 = _nolan.c2
     c3 = _nolan.c3
     g = _nolan.g
-
+    # round x0 to zeta again if needed. zeta was recomputed and may have
+    # changed due to floating point differences.
+    # See https://github.com/scipy/scipy/pull/18133
+    x0 = _nolan_round_x_near_zeta(x0, alpha, zeta, x_tol_near_zeta)
     # handle Nolan's initial case logic
     if (alpha == 1 and beta < 0) or x0 < zeta:
         # NOTE: Nolan's paper has a typo here!
@@ -350,7 +362,7 @@ def _cdf_single_value_piecewise_post_rounding_Z0(x0, alpha, beta, quad_eps):
         # incorrect since F(-infty) would be 1.0 in this case
         # Indeed, the alpha != 1, x0 < zeta case is correct here.
         return 1 - _cdf_single_value_piecewise_post_rounding_Z0(
-            -x0, alpha, -beta, quad_eps
+            -x0, alpha, -beta, quad_eps, x_tol_near_zeta
         )
     elif x0 == zeta:
         return 0.5 - xi / np.pi


Test patch:
diff --git a/scipy/stats/tests/test_distributions.py b/scipy/stats/tests/test_distributions.py
--- a/scipy/stats/tests/test_distributions.py
+++ b/scipy/stats/tests/test_distributions.py
@@ -4484,6 +4484,14 @@ def test_isf(self):
 
 
 class TestLevyStable:
+    @pytest.fixture(autouse=True)
+    def reset_levy_stable_params(self):
+        """Setup default parameters for levy_stable generator"""
+        stats.levy_stable.parameterization = "S1"
+        stats.levy_stable.cdf_default_method = "piecewise"
+        stats.levy_stable.pdf_default_method = "piecewise"
+        stats.levy_stable.quad_eps = stats._levy_stable._QUAD_EPS
+
     @pytest.fixture
     def nolan_pdf_sample_data(self):
         """Sample data points for pdf computed with Nolan's stablec
@@ -5194,6 +5202,98 @@ def test_distribution_outside_support(
             np.full(len(points), expected)
         )
 
+    @pytest.mark.parametrize(
+        'x,alpha,beta,expected',
+        # Reference values from Matlab
+        # format long
+        # alphas = [1.7720732804618808, 1.9217001522410235, 1.5654806051633634,
+        #           1.7420803447784388, 1.5748002527689913];
+        # betas = [0.5059373136902996, -0.8779442746685926, -0.4016220341911392,
+        #          -0.38180029468259247, -0.25200194914153684];
+        # x0s = [0, 1e-4, -1e-4];
+        # for x0 = x0s
+        #     disp("x0 = " + x0)
+        #     for ii = 1:5
+        #         alpha = alphas(ii);
+        #         beta = betas(ii);
+        #         pd = makedist('Stable','alpha',alpha,'beta',beta,'gam',1,'delta',0);
+        #         % we need to adjust x. It is the same as x = 0 In scipy.
+        #         x = x0 - beta * tan(pi * alpha / 2);
+        #         disp(pd.pdf(x))
+        #     end
+        # end
+        [
+            (0, 1.7720732804618808, 0.5059373136902996, 0.278932636798268),
+            (0, 1.9217001522410235, -0.8779442746685926, 0.281054757202316),
+            (0, 1.5654806051633634, -0.4016220341911392, 0.271282133194204),
+            (0, 1.7420803447784388, -0.38180029468259247, 0.280202199244247),
+            (0, 1.5748002527689913, -0.25200194914153684, 0.280136576218665),
+        ]
+    )
+    def test_x_equal_zeta(
+            self, x, alpha, beta, expected
+    ):
+        """Test pdf for x equal to zeta.
+
+        With S1 parametrization: x0 = x + zeta if alpha != 1 So, for x = 0, x0
+        will be close to zeta.
+
+        When case "x equal zeta" is not handled properly and quad_eps is not
+        low enough: - pdf may be less than 0 - logpdf is nan
+
+        The points from the parametrize block are found randomly so that PDF is
+        less than 0.
+
+        Reference values taken from MATLAB
+        https://www.mathworks.com/help/stats/stable-distribution.html
+        """
+        stats.levy_stable.quad_eps = 1.2e-11
+
+        assert_almost_equal(
+            stats.levy_stable.pdf(x, alpha=alpha, beta=beta),
+            expected,
+        )
+
+    @pytest.mark.xfail
+    @pytest.mark.parametrize(
+        # See comment for test_x_equal_zeta for script for reference values
+        'x,alpha,beta,expected',
+        [
+            (1e-4, 1.7720732804618808, 0.5059373136902996, 0.278929165340670),
+            (1e-4, 1.9217001522410235, -0.8779442746685926, 0.281056564327953),
+            (1e-4, 1.5654806051633634, -0.4016220341911392, 0.271252432161167),
+            (1e-4, 1.7420803447784388, -0.38180029468259247, 0.280205311264134),
+            (1e-4, 1.5748002527689913, -0.25200194914153684, 0.280140965235426),
+            (-1e-4, 1.7720732804618808, 0.5059373136902996, 0.278936106741754),
+            (-1e-4, 1.9217001522410235, -0.8779442746685926, 0.281052948629429),
+            (-1e-4, 1.5654806051633634, -0.4016220341911392, 0.271275394392385),
+            (-1e-4, 1.7420803447784388, -0.38180029468259247, 0.280199085645099),
+            (-1e-4, 1.5748002527689913, -0.25200194914153684, 0.280132185432842),
+        ]
+    )
+    def test_x_near_zeta(
+            self, x, alpha, beta, expected
+    ):
+        """Test pdf for x near zeta.
+
+        With S1 parametrization: x0 = x + zeta if alpha != 1 So, for x = 0, x0
+        will be close to zeta.
+
+        When case "x near zeta" is not handled properly and quad_eps is not
+        low enough: - pdf may be less than 0 - logpdf is nan
+
+        The points from the parametrize block are found randomly so that PDF is
+        less than 0.
+
+        Reference values taken from MATLAB
+        https://www.mathworks.com/help/stats/stable-distribution.html
+        """
+        stats.levy_stable.quad_eps = 1.2e-11
+
+        assert_almost_equal(
+            stats.levy_stable.pdf(x, alpha=alpha, beta=beta),
+            expected,
+        )
 
 class TestArrayArgument:  # test for ticket:992
     def setup_method(self):