diff options
| author | eltjpm <evgeny.toder@jpmorgan.com> | 2013-11-08 16:35:06 -0500 |
|---|---|---|
| committer | eltjpm <evgeny.toder@jpmorgan.com> | 2013-11-08 16:35:06 -0500 |
| commit | 819597324c4cf4333120cdf951983681f0732ead (patch) | |
| tree | 66c093928887e29e70249bcbfe1122f7a3fce60d /numpy | |
| parent | f30cecb89264660b5818fedaf7ce1fbb3e35050b (diff) | |
| download | numpy-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.c | 2 | ||||
| -rw-r--r-- | numpy/core/tests/test_regression.py | 7 |
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() |
