[SciPy-dev] possible bug in interp1d

Darren Dale dd55 at cornell.edu
Wed Dec 7 09:21:00 CST 2005

On Wednesday 07 December 2005 07:57, Tyler W. Wilson wrote:
> Well, that fixed the that issue, but now I get the following:
>   File "E:\Python24\Lib\site-packages\scipy\interpolate\interpolate.py",
> line 180, in __call__
>     putmask(y_new, new_out.ravel(), self.fill_value)
>   File "E:\Python24\Lib\site-packages\scipy\base\oldnumeric.py", line
> 170, in putmask
>     return a.putmask(v, mask)
> TypeError: array cannot be safely cast to required type

reminder of the test script:

from scipy import *
a = arange(100)
b = arange(10,90,100)
i = interpolate.interp1d(a,a)

I checked the values of a and v in putmask. a has dtype 'l', and v is nan. I 
dont understand the TypeError, since a[1]=nan doesn't raise one (it just sets 
a[2] equal to 0).
If I change the dtype of a to 'f' and keep b the same,  I get the following:

/usr/lib64/python2.4/site-packages/scipy/interpolate/interpolate.py in 
__call__(self, x_new)
    150         #    would be inserted.
    151         #    Note: If x_new[n] = x[m], then m is returned by 
--> 152         x_new_indices = searchsorted(self.x,x_new)
    153         # 3. Clip x_new_indices so that they are within the range of
    154         #    self.x indices and at least 1.  Removes mis-interpolation

/usr/lib64/python2.4/site-packages/scipy/base/oldnumeric.py in searchsorted(a, 
    235     a = array(a,copy=False)
    236     print a.dtypechar, a, v
--> 237     return a.searchsorted(v)
    239 def resize(a, new_shape):

TypeError: array cannot be safely cast to required type

More information about the Scipy-dev mailing list