summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/convert.c33
-rw-r--r--numpy/core/tests/test_multiarray.py8
2 files changed, 33 insertions, 8 deletions
diff --git a/numpy/core/src/multiarray/convert.c b/numpy/core/src/multiarray/convert.c
index b610343cc..e1c2cb8d9 100644
--- a/numpy/core/src/multiarray/convert.c
+++ b/numpy/core/src/multiarray/convert.c
@@ -350,16 +350,33 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
}
/* Python integer */
else if (PyLong_Check(obj) || PyInt_Check(obj)) {
- npy_longlong v = PyLong_AsLongLong(obj);
- if (v == -1 && PyErr_Occurred()) {
- return -1;
+ /* Try long long before unsigned long long */
+ npy_longlong ll_v = PyLong_AsLongLong(obj);
+ if (ll_v == -1 && PyErr_Occurred()) {
+ /* Long long failed, try unsigned long long */
+ npy_ulonglong ull_v;
+ PyErr_Clear();
+ ull_v = PyLong_AsUnsignedLongLong(obj);
+ if (ull_v == (unsigned long long)-1 && PyErr_Occurred()) {
+ return -1;
+ }
+ value = (char *)value_buffer;
+ *(npy_ulonglong *)value = ull_v;
+
+ dtype = PyArray_DescrFromType(NPY_ULONGLONG);
+ if (dtype == NULL) {
+ return -1;
+ }
}
- value = (char *)value_buffer;
- *(npy_longlong *)value = v;
+ else {
+ /* Long long succeeded */
+ value = (char *)value_buffer;
+ *(npy_longlong *)value = ll_v;
- dtype = PyArray_DescrFromType(NPY_LONGLONG);
- if (dtype == NULL) {
- return -1;
+ dtype = PyArray_DescrFromType(NPY_LONGLONG);
+ if (dtype == NULL) {
+ return -1;
+ }
}
}
/* Python float */
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 33d1ac4a3..f768f3acb 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -193,6 +193,14 @@ class TestAttributes(TestCase):
y[...] = 1
assert_equal(x, y)
+ def test_fill_max_uint64(self):
+ x = empty((3, 2, 1), dtype=uint64)
+ y = empty((3, 2, 1), dtype=uint64)
+ value = 2**64 - 1
+ y[...] = value
+ x.fill(value)
+ assert_array_equal(x, y)
+
def test_fill_struct_array(self):
# Filling from a scalar
x = array([(0, 0.0), (1, 1.0)], dtype='i4,f8')