Commits

Brian Kearns committed 2456057

fix numpy dtype guessing for uint64

  • Participants
  • Parent commits 527f9e5

Comments (0)

Files changed (3)

File pypy/module/micronumpy/interp_ufuncs.py

     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):
     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

File pypy/module/micronumpy/test/test_numarray.py

 
     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)
         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

File pypy/module/micronumpy/test/test_scalar.py

         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