summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/common.c10
-rw-r--r--numpy/core/tests/test_multiarray.py23
2 files changed, 31 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c
index f62b37b4d..82c2b8f71 100644
--- a/numpy/core/src/multiarray/common.c
+++ b/numpy/core/src/multiarray/common.c
@@ -36,9 +36,15 @@ _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) == -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 99861748c..1d55a0ce6 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -2377,6 +2377,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):