<p dir="auto">I am having an issue with some unexpected behaviour with the <code class="notranslate">scipy.interpolate.interp1d</code> method for the following kinds:</p>
<ul dir="auto">
<li><code class="notranslate">kind= ['nearest','linear', 'previous' and 'next']</code> (i.e. kinds not involving spline interpolation according to the doc)</li>
</ul>
<p dir="auto">When providing non-strictly monotonic <code class="notranslate">x</code> values, unexpected results are returned rather than the method failing:</p>
<h3 dir="auto">Reproducing code example:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
from scipy.interpolate import interp1d

x = np.array([0, 1, 1])
y = np.array([0, 1, 0])

for kind in ['nearest', 'linear', 'previous', 'next']:
    f = interp1d(x,y,kind=kind)
    print(&quot;{k}: &quot;.format(k=kind), f(x))"><pre class="notranslate"><code class="notranslate">import numpy as np
from scipy.interpolate import interp1d

x = np.array([0, 1, 1])
y = np.array([0, 1, 0])

for kind in ['nearest', 'linear', 'previous', 'next']:
    f = interp1d(x,y,kind=kind)
    print("{k}: ".format(k=kind), f(x))
</code></pre></div>
<h3 dir="auto">Output</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="nearest:  [0. 1. 1.]
linear:  [0. 1. 1.]
previous:  [0. 0. 0.]
next:  [0. 1. 1.]"><pre class="notranslate"><code class="notranslate">nearest:  [0. 1. 1.]
linear:  [0. 1. 1.]
previous:  [0. 0. 0.]
next:  [0. 1. 1.]
</code></pre></div>
<h3 dir="auto">Error message:</h3>
<p dir="auto">For <code class="notranslate">kind='cubic'</code> it fails in a similar matter as I would expect it to for the others:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-30-064ad468e798&gt; in &lt;module&gt;
----&gt; 1 f = interp1d(x,y,kind='cubic')
      2 f(x)

C:\anaconda\envs\atlite\lib\site-packages\scipy\interpolate\interpolate.py in __init__(***failed resolving arguments***)
    533 
    534             self._spline = make_interp_spline(xx, yy, k=order,
--&gt; 535                                               check_finite=False)
    536             if rewrite_nan:
    537                 self._call = self.__class__._call_nan_spline

C:\anaconda\envs\atlite\lib\site-packages\scipy\interpolate\_bsplines.py in make_interp_spline(x, y, k, t, bc_type, axis, check_finite)
    797 
    798     if x.ndim != 1 or np.any(x[1:] &lt;= x[:-1]):
--&gt; 799         raise ValueError(&quot;Expect x to be a 1-D sorted array_like.&quot;)
    800     if k &lt; 0:
    801         raise ValueError(&quot;Expect non-negative k.&quot;)

ValueError: Expect x to be a 1-D sorted array_like."><pre class="notranslate"><code class="notranslate">---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-30-064ad468e798&gt; in &lt;module&gt;
----&gt; 1 f = interp1d(x,y,kind='cubic')
      2 f(x)

C:\anaconda\envs\atlite\lib\site-packages\scipy\interpolate\interpolate.py in __init__(***failed resolving arguments***)
    533 
    534             self._spline = make_interp_spline(xx, yy, k=order,
--&gt; 535                                               check_finite=False)
    536             if rewrite_nan:
    537                 self._call = self.__class__._call_nan_spline

C:\anaconda\envs\atlite\lib\site-packages\scipy\interpolate\_bsplines.py in make_interp_spline(x, y, k, t, bc_type, axis, check_finite)
    797 
    798     if x.ndim != 1 or np.any(x[1:] &lt;= x[:-1]):
--&gt; 799         raise ValueError("Expect x to be a 1-D sorted array_like.")
    800     if k &lt; 0:
    801         raise ValueError("Expect non-negative k.")

ValueError: Expect x to be a 1-D sorted array_like.
</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="[1]: import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)
1.2.1 1.15.4 sys.version_info(major=3, minor=6, micro=6, releaselevel='final', serial=0)
"><pre class="notranslate"><code class="notranslate">[1]: import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)
1.2.1 1.15.4 sys.version_info(major=3, minor=6, micro=6, releaselevel='final', serial=0)

</code></pre></div>
<p dir="auto">Code: see the post <a href="https://stackoverflow.com/questions/46983476/" rel="nofollow">https://stackoverflow.com/questions/46983476/</a></p>
<p dir="auto">Got error message:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/57449793/100565882-7f605100-32ff-11eb-9656-48c0232feb2a.png"><img src="https://user-images.githubusercontent.com/57449793/100565882-7f605100-32ff-11eb-9656-48c0232feb2a.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">The error message <code class="notranslate">Invalid input data</code> is uninformative.<br>
Is it possible to provide the reason or solution of the error in the error message?</p>