Author: Brian Kearns <[email protected]>
Branch:
Changeset: r68535:245605722af8
Date: 2013-12-24 14:57 -0500
http://bitbucket.org/pypy/pypy/changeset/245605722af8/
Log: fix numpy dtype guessing for uint64
diff --git a/pypy/module/micronumpy/interp_ufuncs.py
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -532,6 +532,7 @@
bool_dtype = interp_dtype.get_dtype_cache(space).w_booldtype
long_dtype = interp_dtype.get_dtype_cache(space).w_longdtype
int64_dtype = interp_dtype.get_dtype_cache(space).w_int64dtype
+ uint64_dtype = interp_dtype.get_dtype_cache(space).w_uint64dtype
complex_type = interp_dtype.get_dtype_cache(space).w_complex128dtype
float_type = interp_dtype.get_dtype_cache(space).w_float64dtype
if isinstance(w_obj, interp_boxes.W_GenericBox):
@@ -552,7 +553,15 @@
elif space.isinstance_w(w_obj, space.w_long):
if (current_guess is None or current_guess is bool_dtype or
current_guess is long_dtype or current_guess is int64_dtype):
- return int64_dtype
+ try:
+ space.int_w(w_obj)
+ except OperationError, e:
+ if e.match(space, space.w_OverflowError):
+ return uint64_dtype
+ else:
+ raise
+ else:
+ return int64_dtype
return current_guess
elif space.isinstance_w(w_obj, space.w_complex):
if (current_guess is None or current_guess is bool_dtype or
diff --git a/pypy/module/micronumpy/test/test_numarray.py
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -1506,7 +1506,7 @@
def test_dtype_guessing(self):
from numpypy import array, dtype
-
+ import sys
assert array([True]).dtype is dtype(bool)
assert array([True, False]).dtype is dtype(bool)
assert array([True, 1]).dtype is dtype(int)
@@ -1522,6 +1522,7 @@
assert array([int8(3)]).dtype is dtype("int8")
assert array([bool_(True)]).dtype is dtype(bool)
assert array([bool_(True), 3.0]).dtype is dtype(float)
+ assert array(sys.maxint + 42).dtype is dtype('Q')
def test_comparison(self):
import operator
diff --git a/pypy/module/micronumpy/test/test_scalar.py
b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -20,7 +20,7 @@
assert math.isnan(np.complex_(None))
for c in ['i', 'I', 'l', 'L', 'q', 'Q']:
assert np.dtype(c).type().dtype.char == c
- assert np.dtype('L').type(sys.maxint + 42)
+ assert np.dtype('L').type(sys.maxint + 42) == sys.maxint + 42
def test_builtin(self):
import numpy as np
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit