summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-02-09 11:22:55 +0000
committerEric Wieser <wieser.eric@gmail.com>2017-02-10 18:28:07 +0000
commitfa040cada9e832a6d23f359a4029953d14acca0a (patch)
treea64395aaa2c25966399aee341ef60be7b65987cb /numpy
parent1b877254af0850d025cdc5d07b3fcaa1614dbe4b (diff)
downloadnumpy-fa040cada9e832a6d23f359a4029953d14acca0a.tar.gz
BUG: make np.squeeze always return an array, never a scalar
Fixes #8588
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src3
-rw-r--r--numpy/core/tests/test_numeric.py3
2 files changed, 4 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index f85e3b828..db7cad21b 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -1579,8 +1579,7 @@ gentype_squeeze(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "")) {
return NULL;
}
- Py_INCREF(self);
- return self;
+ return PyArray_FromScalar(self, NULL);
}
static Py_ssize_t
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index 4aa6bed33..919e49061 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -147,6 +147,9 @@ class TestNonarrayArgs(TestCase):
A = [[[1, 1, 1], [2, 2, 2], [3, 3, 3]]]
assert_(np.squeeze(A).shape == (3, 3))
+ assert_(isinstance(np.squeeze(1), np.ndarray))
+ assert_(isinstance(np.squeeze(np.int32(1)), np.ndarray))
+
def test_std(self):
A = [[1, 2, 3], [4, 5, 6]]
assert_almost_equal(np.std(A), 1.707825127659933)