1. Pypy
  2. Untitled project
  3. pypy

Commits

Brian Kearns  committed 0dcf482

fix numpy int coerce cases

  • Participants
  • Parent commits 5078f60
  • Branches default

Comments (0)

Files changed (2)

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

View file
  • Ignore whitespace
         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) == sys.maxint + 42
+        for c in ['l', 'q']:
+            assert np.dtype(c).type(sys.maxint) == sys.maxint
+        for c in ['L', 'Q']:
+            assert np.dtype(c).type(sys.maxint + 42) == sys.maxint + 42
 
     def test_builtin(self):
         import numpy as np

File pypy/module/micronumpy/types.py

View file
  • Ignore whitespace
     BoxType = interp_boxes.W_Int64Box
     format_code = "q"
 
-    _coerce = func_with_new_name(_int64_coerce, '_coerce')
+    if LONG_BIT == 32:
+        _coerce = func_with_new_name(_int64_coerce, '_coerce')
 
 def _uint64_coerce(self, space, w_item):
     try:
     BoxType = interp_boxes.W_LongBox
     format_code = "l"
 
-    if LONG_BIT == 64:
-        _coerce = func_with_new_name(_int64_coerce, '_coerce')
+def _ulong_coerce(self, space, w_item):
+    try:
+        return self._base_coerce(space, w_item)
+    except OperationError, e:
+        if not e.match(space, space.w_OverflowError):
+            raise
+    bigint = space.bigint_w(w_item)
+    try:
+        value = bigint.touint()
+    except OverflowError:
+        raise OperationError(space.w_OverflowError, space.w_None)
+    return self.box(value)
 
 class ULong(BaseType, Integer):
     T = rffi.ULONG
     BoxType = interp_boxes.W_ULongBox
     format_code = "L"
 
-    if LONG_BIT == 64:
-        _coerce = func_with_new_name(_uint64_coerce, '_coerce')
+    _coerce = func_with_new_name(_ulong_coerce, '_coerce')
 
 class Float(Primitive):
     _mixin_ = True