summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/common.c11
-rw-r--r--numpy/core/tests/test_multiarray.py23
2 files changed, 33 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c
index f62b37b4d..123ec62e7 100644
--- a/numpy/core/src/multiarray/common.c
+++ b/numpy/core/src/multiarray/common.c
@@ -36,9 +36,18 @@ _array_find_python_scalar_type(PyObject *op)
/* if integer can fit into a longlong then return that*/
if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {
PyErr_Clear();
+ if ((PyLong_AsUnsignedLongLong(op) == (unsigned long long) -1)
+ && PyErr_Occurred()){
+ PyErr_Clear();
+ }
+ else {
+ return PyArray_DescrFromType(NPY_ULONGLONG);
+ }
return PyArray_DescrFromType(NPY_OBJECT);
}
- return PyArray_DescrFromType(NPY_LONGLONG);
+ else {
+ return PyArray_DescrFromType(NPY_LONGLONG);
+ }
}
return NULL;
}
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index e3e24fae1..d0502149f 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -2425,6 +2425,29 @@ class TestWarnings(object):
finally:
warn_ctx.__exit__()
+class TestMinScalarType(object):
+ def test_usigned_shortshort(self):
+ dt = np.min_scalar_type(2**8-1)
+ wanted = np.dtype('uint8')
+ assert_equal(wanted, dt)
+ def test_usigned_short(self):
+ dt = np.min_scalar_type(2**16-1)
+ wanted = np.dtype('uint16')
+ assert_equal(wanted, dt)
+ def test_usigned_int(self):
+ dt = np.min_scalar_type(2**32-1)
+ wanted = np.dtype('uint32')
+ assert_equal(wanted, dt)
+ def test_usigned_longlong(self):
+ dt = np.min_scalar_type(2**63-1)
+ wanted = np.dtype('uint64')
+ assert_equal(wanted, dt)
+ def test_object(self):
+ dt = np.min_scalar_type(2**64)
+ wanted = np.dtype('O')
+ assert_equal(wanted, dt)
+
+
if sys.version_info >= (2, 6):
if sys.version_info[:2] == (2, 6):