<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/1764" rel="nofollow">http://projects.scipy.org/scipy/ticket/1764</a> on 2012-11-03 by trac user theyoud, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/pv/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/pv">@pv</a>.</em></p>
<p dir="auto">Interpolation (and spline) functions, such as interpolation.interp1d, currently require the array of independent variables (x values) be given in ascending order.  These functions could be enhanced to also accept descending order.  Such a modification would avoid unnecessary reversing of arrays.  Also it would make the routines harder to break.</p>
<p dir="auto">Currently if an array in descending order is specified for x, the behavior is problematic.  The interpolation function is created without error, but when you try to evaluate the interpolation function (at an x value that is in range) you get an error message that the x value is out of range.</p>
<p dir="auto">The following code illustrates the problem I describe above:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
from scipy.interpolate import interp1d

xa = np.arange(10)[::-1]
ya = xa**2
f = interp1d(xa , ya)
f(5.5)"><pre class="notranslate"><code class="notranslate">import numpy as np
from scipy.interpolate import interp1d

xa = np.arange(10)[::-1]
ya = xa**2
f = interp1d(xa , ya)
f(5.5)
</code></pre></div>
<p dir="auto">While the interpolation fn. f is created, there is an error on the attempted evaluation.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ValueError: A value in x_new is below the interpolation range."><pre class="notranslate"><code class="notranslate">ValueError: A value in x_new is below the interpolation range.
</code></pre></div>
<p dir="auto">It's probably a "bug" to create a non-functioning interpolation fn.  The better "enhancement" is probably to accept both ascending and descending order.</p>
<h3 dir="auto">Describe your issue.</h3>
<p dir="auto">Hi all,</p>
<p dir="auto">Our Valgrind CICD run broke after upgrading to Scipy &gt;= 1.9.2 from 1.9.1.<br>
The error does not occur without valgrind.</p>
<p dir="auto">Due to the valgrind involvement making an MRE is though. If needed I can create a MRE repo and add a maintainer.</p>
<p dir="auto">Some additional info:</p>
<ul dir="auto">
<li>OS: Ubuntu-latest</li>
<li>valgrind amd64 1:3.15.0-1ubuntu9.1</li>
</ul>
<p dir="auto">Bindings and generator:</p>
<ul dir="auto">
<li>Pybind11 v2.10.1</li>
<li>ninja v1.10.2.4</li>
</ul>
<p dir="auto">Extension does include a number of Numpy headers but nothing special.</p>
<p dir="auto">Valgrind is run with:</p>
<p dir="auto"><code class="notranslate">PYTHONMALLOC=malloc valgrind --leak-check=yes --track-origins=yes  python -m pytest</code></p>
<p dir="auto">See <a href="https://github.com/RUrlus/ModelMetricUncertainty/blob/stable/.github/workflows/valgrind.yml">Workflow file</a> for details.</p>
<h3 dir="auto">Reproducing Code Example</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import scipy.stats"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">scipy</span>.<span class="pl-s1">stats</span></pre></div>
<h3 dir="auto">Error message</h3>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/sklearn/utils/fixes.py:19: in &lt;module&gt;
    import scipy.stats
/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/scipy/stats/__init__.py:467: in &lt;module&gt;
    from ._stats_py import *
/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/scipy/stats/_stats_py.py:46: in &lt;module&gt;
    from . import distributions
/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/scipy/stats/distributions.py:10: in &lt;module&gt;
    from . import _continuous_distns
/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/scipy/stats/_continuous_distns.py:31: in &lt;module&gt;
    import scipy.stats._boost as _boost
/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/scipy/stats/_boost/__init__.py:1: in &lt;module&gt;
    from scipy.stats._boost.beta_ufunc import (
E   SystemError: initialization of beta_ufunc raised unreported exception"><pre class="notranslate">/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/sklearn/utils/fixes.py:19: <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    import scipy.stats
/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/scipy/stats/__init__.py:467: <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from ._stats_py import <span class="pl-k">*</span>
/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/scipy/stats/_stats_py.py:46: <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from <span class="pl-c1">.</span> import distributions
/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/scipy/stats/distributions.py:10: <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from <span class="pl-c1">.</span> import _continuous_distns
/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/scipy/stats/_continuous_distns.py:31: <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    import scipy.stats._boost as _boost
/opt/hostedtoolcache/Python/3.10.7/x64/lib/python3.10/site-packages/scipy/stats/_boost/__init__.py:1: <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from scipy.stats._boost.beta_ufunc import (
E   SystemError: initialization of beta_ufunc raised unreported exception</pre></div>
<h3 dir="auto">SciPy/NumPy/Python version information</h3>
<p dir="auto">1.9.3 1.23.3 sys.version_info(major=3, minor=10, micro=7, releaselevel='final', serial=0)</p>