diff options
author | Eric Fode <ericfode@linuxlaptop.(none)> | 2012-07-10 14:09:44 -0400 |
---|---|---|
committer | Eric Fode <ericfode@gmail.com> | 2012-07-14 13:35:18 -0400 |
commit | 6966bdcf28ec709e794d4b0c65cb72b0275d8e92 (patch) | |
tree | 3e8a69e2471385268f8727210a8e4a4673a5f4c1 | |
parent | 6a1ab0382a8a7e7415277231fedc0ee1ef60326c (diff) | |
download | numpy-6966bdcf28ec709e794d4b0c65cb72b0275d8e92.tar.gz |
BUG: ticket #2028: When min_scalar was not checking to see if numbers could fit into unsigned long longs. This was fixed by adding an extra case to function to check if the passed number could fit into a unsigned long long if it could not fit into anything else. Additionaly, regression tests were added.
-rw-r--r-- | numpy/core/src/multiarray/common.c | 10 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 23 |
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): |