<p dir="auto">&lt;&lt;Please describe the issue in detail here, and for bug reports fill in the fields below.&gt;&gt;<br>
I want to use interpolate.splprep but it returns SystemError</p>
<h3 dir="auto">Reproducing code example:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from scipy import interpolate
A = [-50.49072266, -50.49072266, -54.49072266, -54.49072266]
tck, t = interpolate.splprep([A])"><pre class="notranslate"><code class="notranslate">from scipy import interpolate
A = [-50.49072266, -50.49072266, -54.49072266, -54.49072266]
tck, t = interpolate.splprep([A])
</code></pre></div>
<h3 dir="auto">Error message:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="*** SystemError: &lt;built-in function _parcur&gt; returned NULL without setting an error"><pre class="notranslate"><code class="notranslate">*** SystemError: &lt;built-in function _parcur&gt; returned NULL without setting an error
</code></pre></div>
<h3 dir="auto">Scipy/Numpy/Python version information:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="0.19.0 1.12.1 sys.version_info(major=3, minor=6, micro=1, releaselevel='final', serial=0)"><pre class="notranslate"><code class="notranslate">0.19.0 1.12.1 sys.version_info(major=3, minor=6, micro=1, releaselevel='final', serial=0)
</code></pre></div>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/978" rel="nofollow">http://projects.scipy.org/scipy/ticket/978</a> on 2009-07-28 by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/josef-pkt/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/josef-pkt">@josef-pkt</a>, assigned to unknown.</em></p>
<p dir="auto">floating point errors in ceil is not corrected in nbinom._ppf</p>
<p dir="auto">PierreGM</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" &gt;&gt;&gt; from scipy.stats.distributions import nbinom
 &gt;&gt;&gt;  nbinom(.3,.15).ppf(nbinom(.3,.15).cdf(np.arange(20)))
array([  1.,   2.,   2.,   3.,   5.,   5.,   6.,   8.,   9.,  10.,  11.,
        12.,  13.,  14.,  15.,  16.,  17.,  18.,  19.,  20.])

I would have naturally expected np.arange(20)."><pre class="notranslate"><code class="notranslate"> &gt;&gt;&gt; from scipy.stats.distributions import nbinom
 &gt;&gt;&gt;  nbinom(.3,.15).ppf(nbinom(.3,.15).cdf(np.arange(20)))
array([  1.,   2.,   2.,   3.,   5.,   5.,   6.,   8.,   9.,  10.,  11.,
        12.,  13.,  14.,  15.,  16.,  17.,  18.,  19.,  20.])

I would have naturally expected np.arange(20).
</code></pre></div>
<p dir="auto">Robert Kern:</p>
<p dir="auto">The problem here is that we are using nbdtr() inside this function to compute temp, but nbdtr doesn't handle n&lt;1. The _cdf() method uses betainc() instead. If one replaces these lines:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" vals1 = vals-1
 temp = special.nbdtr(vals1,n,pr)"><pre class="notranslate"><code class="notranslate"> vals1 = vals-1
 temp = special.nbdtr(vals1,n,pr)
</code></pre></div>
<p dir="auto">with these:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" vals1 = (vals-1).clip(0.0, np.inf)
 temp = special.betainc(n,vals,pr)"><pre class="notranslate"><code class="notranslate"> vals1 = (vals-1).clip(0.0, np.inf)
 temp = special.betainc(n,vals,pr)
</code></pre></div>
<p dir="auto">then you get the desired answer.</p>
<p dir="auto">josef:</p>
<p dir="auto">It would be better to replace the duplication of the _cdf method directly with a call to self._cdf.<br>
For example, in changeset 4673,  _cdf method was changed to use betainc instead of nbdtr, but not the _ppf method. Without the code duplication, partial corrections could be more easily avoided.</p>
<p dir="auto">add roundtrip test to all discrete distributions, like</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; n=10
&gt;&gt;&gt; (nbinom(n,0.15).ppf(nbinom(n,0.15).cdf(np.arange(100)))==np.arange(100)).all()
True
&gt;&gt;&gt; n=0.3
&gt;&gt;&gt; (nbinom(n,0.15).ppf(nbinom(n,0.15).cdf(np.arange(100)))==np.arange(100)).all()
False"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; n=10
&gt;&gt;&gt; (nbinom(n,0.15).ppf(nbinom(n,0.15).cdf(np.arange(100)))==np.arange(100)).all()
True
&gt;&gt;&gt; n=0.3
&gt;&gt;&gt; (nbinom(n,0.15).ppf(nbinom(n,0.15).cdf(np.arange(100)))==np.arange(100)).all()
False
</code></pre></div>