[Numpy-svn] r5218 - in trunk/numpy/core: src tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Wed May 21 22:02:42 EDT 2008
Author: cdavid
Date: 2008-05-21 21:02:36 -0500 (Wed, 21 May 2008)
New Revision: 5218
Modified:
trunk/numpy/core/src/multiarraymodule.c
trunk/numpy/core/tests/test_regression.py
Log:
Fix #789 by Alan Mcintyre.
Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c 2008-05-21 23:16:02 UTC (rev 5217)
+++ trunk/numpy/core/src/multiarraymodule.c 2008-05-22 02:02:36 UTC (rev 5218)
@@ -3895,7 +3895,16 @@
}
obj = (PyArrayObject *)PyArray_FromArray(ret, self->descr,
flags);
- if (obj != ret) copyret = 1;
+ if (obj == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "unable to create array of proper type from output array");
+ ret = NULL;
+ Py_DECREF(self->descr);
+ goto fail;
+ }
+ else if (obj != ret) {
+ copyret = 1;
+ }
ret = obj;
}
Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py 2008-05-21 23:16:02 UTC (rev 5217)
+++ trunk/numpy/core/tests/test_regression.py 2008-05-22 02:02:36 UTC (rev 5218)
@@ -1038,6 +1038,22 @@
assert (xp.__array_interface__['data'][0] !=
xpd.__array_interface__['data'][0])
+ def check_compress_small_type(self, level=rlevel):
+ """Ticket #789, changeset 5217.
+ """
+ # compress with out argument segfaulted if cannot cast safely
+ import numpy as np
+ a = np.array([[1, 2], [3, 4]])
+ b = np.zeros((2, 1), dtype = np.single)
+ try:
+ a.compress([True, False], axis = 1, out = b)
+ raise AssertionError("compress with an out which cannot be " \
+ "safely casted should not return "\
+ "successfully")
+ except ValueError:
+ pass
+
+
def check_recarray_tolist(self, level=rlevel):
"""Ticket #793, changeset r5215
"""
More information about the Numpy-svn
mailing list