[Scipy-svn] r5056 - in trunk/scipy/interpolate: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Mon Nov 10 18:03:52 EST 2008
Author: ptvirtan
Date: 2008-11-10 17:03:38 -0600 (Mon, 10 Nov 2008)
New Revision: 5056
Modified:
trunk/scipy/interpolate/interpolate.py
trunk/scipy/interpolate/tests/test_interpolate.py
Log:
Ensure interp1d.__call__ always returns an ndarray, not an array scalar, for 0-dim output.
Modified: trunk/scipy/interpolate/interpolate.py
===================================================================
--- trunk/scipy/interpolate/interpolate.py 2008-11-10 22:50:30 UTC (rev 5055)
+++ trunk/scipy/interpolate/interpolate.py 2008-11-10 23:03:38 UTC (rev 5056)
@@ -295,7 +295,7 @@
Returns
-------
- y_new : number or array
+ y_new : ndarray
Interpolated value(s) corresponding to x_new.
"""
@@ -323,10 +323,10 @@
# special case: x is a scalar
if out_of_bounds:
if ny == 0:
- return self.fill_value
+ return asarray(self.fill_value)
else:
y_new[...] = self.fill_value
- return y_new
+ return asarray(y_new)
elif self._kind == 'linear':
y_new[..., out_of_bounds] = self.fill_value
axes = range(ny - nx)
Modified: trunk/scipy/interpolate/tests/test_interpolate.py
===================================================================
--- trunk/scipy/interpolate/tests/test_interpolate.py 2008-11-10 22:50:30 UTC (rev 5055)
+++ trunk/scipy/interpolate/tests/test_interpolate.py 2008-11-10 23:03:38 UTC (rev 5056)
@@ -186,6 +186,7 @@
def _nd_check(self, kind='linear'):
""" Check the behavior when the inputs and outputs are multidimensional.
"""
+
# Multidimensional input.
interp10 = interp1d(self.x10, self.y10, kind=kind)
assert_array_almost_equal(
@@ -193,6 +194,10 @@
np.array([[3.4, 5.6], [2.4, 7.8]]),
)
+ # Scalar input -> 0-dim scalar array output
+ self.failUnless(isinstance(interp10(1.2), np.ndarray))
+ assert_equal(interp10(1.2).shape, ())
+
# Multidimensional outputs.
interp210 = interp1d(self.x10, self.y210, kind=kind)
assert_array_almost_equal(
More information about the Scipy-svn
mailing list