diff options
author | Travis E. Oliphant <teoliphant@gmail.com> | 2012-07-17 21:45:48 -0500 |
---|---|---|
committer | Travis E. Oliphant <teoliphant@gmail.com> | 2012-07-17 21:45:48 -0500 |
commit | 7b8d30b4c1dc0f33d9988d47de24c77cbeea41f8 (patch) | |
tree | 92a20806378c174bf6937703598de3e5b5c0dfe8 /numpy | |
parent | bc1005324566269d016ad9c17a25b43c6b9fc1de (diff) | |
parent | 78f66726040a87d3d0955f1d437c5a7c745bc632 (diff) | |
download | numpy-7b8d30b4c1dc0f33d9988d47de24c77cbeea41f8.tar.gz |
Merge remote-tracking branch 'hackerschool/2028fix'
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/common.c | 11 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 23 |
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): |