summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wiebe <mwwiebe@gmail.com>2011-08-18 12:40:49 -0700
committerCharles Harris <charlesr.harris@gmail.com>2011-08-27 07:26:56 -0600
commit73be11db794d115a7d9bd2e822c0d8008bc14a28 (patch)
tree4029a8a8160d6e4692ed69eed244aafab8deaa46
parentc8732958c8e07f2306029dfde2178faf9c01d049 (diff)
downloadnumpy-73be11db794d115a7d9bd2e822c0d8008bc14a28.tar.gz
BUG: Some bugs in squeeze and concatenate found by testing SciPy
-rw-r--r--numpy/core/fromnumeric.py7
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c8
-rw-r--r--numpy/lib/tests/test_index_tricks.py4
-rw-r--r--numpy/lib/tests/test_shape_base.py7
4 files changed, 21 insertions, 5 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py
index 12cdbd68a..f3930eaa9 100644
--- a/numpy/core/fromnumeric.py
+++ b/numpy/core/fromnumeric.py
@@ -905,7 +905,12 @@ def squeeze(a, axis=None):
squeeze = a.squeeze
except AttributeError:
return _wrapit(a, 'squeeze')
- return squeeze(axis=axis)
+ try:
+ # First try to use the new axis= parameter
+ return squeeze(axis=axis)
+ except TypeError:
+ # For backwards compatibility
+ return squeeze()
def diagonal(a, offset=0, axis1=0, axis2=1):
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index 2afb0d84a..26709d290 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -339,11 +339,11 @@ PyArray_ConcatenateArrays(int narrays, PyArrayObject **arrays, int axis)
/* Handle standard Python negative indexing */
if (axis < 0) {
- axis += narrays;
+ axis += ndim;
}
if (axis < 0 || axis >= ndim) {
- PyErr_SetString(PyExc_IndexError,
- "axis out of bounds");
+ PyErr_Format(PyExc_IndexError,
+ "axis %d out of bounds [0, %d)", axis, ndim);
return NULL;
}
@@ -530,7 +530,7 @@ PyArray_ConcatenateFlattenedArrays(int narrays, PyArrayObject **arrays,
}
strides[1] = dtype->elsize;
- strides[2] = strides[1] * shape[1];
+ strides[0] = strides[1] * shape[1];
/* Allocate the array for the result. This steals the 'dtype' reference. */
ret = (PyArrayObject *)PyArray_NewFromDescr(subtype,
diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py
index e4c0bde93..2c6500a57 100644
--- a/numpy/lib/tests/test_index_tricks.py
+++ b/numpy/lib/tests/test_index_tricks.py
@@ -147,6 +147,10 @@ class TestIndexExpression(TestCase):
assert_equal(a[:,:3,[1,2]], a[index_exp[:,:3,[1,2]]])
assert_equal(a[:,:3,[1,2]], a[s_[:,:3,[1,2]]])
+def test_c_():
+ a = np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
+ assert_equal(a, [[1, 2, 3, 0, 0, 4, 5, 6]])
+
def test_fill_diagonal():
a = zeros((3, 3),int)
fill_diagonal(a, 5)
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py
index 9d6cd0551..56178e8af 100644
--- a/numpy/lib/tests/test_shape_base.py
+++ b/numpy/lib/tests/test_shape_base.py
@@ -258,6 +258,13 @@ class TestSqueeze(TestCase):
assert_array_equal(squeeze(b),reshape(b,(20,10,20)))
assert_array_equal(squeeze(c),reshape(c,(20,10)))
+ # Squeezing to 0-dim should still give an ndarray
+ a = [[[1.5]]]
+ res = squeeze(a)
+ assert_equal(res, 1.5)
+ assert_equal(res.ndim, 0)
+ assert_equal(type(res), ndarray)
+
class TestKron(TestCase):
def test_return_type(self):