summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authoreltjpm <evgeny.toder@jpmorgan.com>2013-11-08 16:35:06 -0500
committereltjpm <evgeny.toder@jpmorgan.com>2013-11-08 16:35:06 -0500
commit819597324c4cf4333120cdf951983681f0732ead (patch)
tree66c093928887e29e70249bcbfe1122f7a3fce60d /numpy
parentf30cecb89264660b5818fedaf7ce1fbb3e35050b (diff)
downloadnumpy-819597324c4cf4333120cdf951983681f0732ead.tar.gz
BUG: Fix raising exception on invalid assignment from sequence
Closes gh-4024
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/ctors.c2
-rw-r--r--numpy/core/tests/test_regression.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index a897169a3..a47b8625a 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -412,7 +412,7 @@ setArrayFromSequence(PyArrayObject *a, PyObject *s,
int dim, PyArrayObject * dst)
{
Py_ssize_t i, slen;
- int res = 0;
+ int res = -1;
/* first recursion, view equal destination */
if (dst == NULL)
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index b98746e1b..23a71d2f1 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1922,5 +1922,12 @@ class TestRegression(TestCase):
[sixu('F'), sixu('o'), sixu('o'), sixu('b'), sixu('')]]])
assert_array_equal(arr, arr2)
+ def test_assign_from_sequence_error(self):
+ # Ticket #4024.
+ arr = np.array([1, 2, 3])
+ assert_raises(ValueError, arr.__setitem__, slice(None), [9, 9])
+ arr.__setitem__(slice(None), [9])
+ assert_equal(arr, [9, 9, 9])
+
if __name__ == "__main__":
run_module_suite()