[pypy-commit] pypy object-dtype2: add tests, fixes for tests
mattip
noreply at buildbot.pypy.org
Fri Apr 3 08:02:49 CEST 2015
Author: mattip <matti.picus at gmail.com>
Branch: object-dtype2
Changeset: r76697:077446240bbd
Date: 2015-04-03 09:03 +0300
http://bitbucket.org/pypy/pypy/changeset/077446240bbd/
Log: add tests, fixes for tests
diff --git a/pypy/module/micronumpy/test/test_object_arrays.py b/pypy/module/micronumpy/test/test_object_arrays.py
--- a/pypy/module/micronumpy/test/test_object_arrays.py
+++ b/pypy/module/micronumpy/test/test_object_arrays.py
@@ -28,6 +28,23 @@
res = a + b
assert res[0] == "foobar"
+ def test_bool_func(self):
+ import numpy as np
+ a = np.array(["foo"], dtype=object)
+ b = a and complex(1, -1)
+ assert b == complex(1, -1)
+ b = complex(1, -1) and a
+ assert (b == a).all()
+
+ def test_logical_ufunc(self):
+ import numpy as np
+ a = np.array(["foo"], dtype=object)
+ b = np.array([1], dtype=object)
+ raises(TypeError, np.logical_and, a, 1)
+ raises(TypeError, np.logical_and, b, complex(1, -1))
+ c = b & 1
+ assert (c == b).all()
+
def test_reduce(self):
import numpy as np
class O(object):
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1697,6 +1697,11 @@
"cannot create object array/scalar from lltype")
return self.BoxType(w_obj)
+ @specialize.argtype(1, 2)
+ def box_complex(self, real, imag):
+ w_obj = self.space.newcomplex(real, imag)
+ return self.BoxType(w_obj)
+
def str_format(self, box):
return 'Object as string'
#return space.str_w(space.repr(self.unbox(box)))
@@ -1728,8 +1733,14 @@
def arctan2(self, v1, v2):
raise oefmt(self.space.w_AttributeError, 'arctan2')
- @specialize.argtype(1)
+ @raw_unary_op
+ def bool(self,v):
+ return not self.space.is_w(v, self.space.w_None) and \
+ not self.space.eq_w(v, self.space.wrap(0)) and \
+ not self.space.len_w(v) == 0
+
def _bool(self, v):
+ #assert isinstance(v, W_Root)
return self.space.bool_w(v)
@raw_binary_op
More information about the pypy-commit
mailing list