Author: Matti Picus <[email protected]>
Branch: numpypy-problems
Changeset: r58241:45b875bca4f1
Date: 2012-10-19 11:42 +0200
http://bitbucket.org/pypy/pypy/changeset/45b875bca4f1/

Log:    disallow ufuncs, binfuncs, operators on flexible types, start to
        test repr()

diff --git a/pypy/module/micronumpy/__init__.py 
b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -62,6 +62,7 @@
         'flexible': 'interp_boxes.W_FlexibleBox',
         'character': 'interp_boxes.W_CharacterBox',
         'str_': 'interp_boxes.W_StringBox',
+        'string_': 'interp_boxes.W_StringBox',
         'unicode_': 'interp_boxes.W_UnicodeBox',
         'void': 'interp_boxes.W_VoidBox',
         'complexfloating': 'interp_boxes.W_ComplexFloatingBox',
diff --git a/pypy/module/micronumpy/interp_dtype.py 
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -143,6 +143,9 @@
     def is_record_type(self):
         return self.fields is not None
 
+    def is_flexible_type(self):
+        return (self.num == 18 or self.num == 19 or self.num == 20)
+
     def __repr__(self):
         if self.fields is not None:
             return '<DType %r>' % self.fields
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
@@ -150,6 +150,9 @@
                 "supported for binary functions"))
         assert isinstance(self, W_Ufunc2)
         obj = convert_to_array(space, w_obj)
+        if obj.get_dtype().is_flexible_type():
+            raise OperationError(space.w_TypeError, 
+                      space.wrap('cannot perform reduce for flexible type'))
         obj_shape = obj.get_shape()
         if obj.is_scalar():
             return obj.get_scalar_value()
@@ -235,6 +238,9 @@
             if space.is_w(out, space.w_None):
                 out = None
         w_obj = convert_to_array(space, w_obj)
+        if w_obj.get_dtype().is_flexible_type():
+            raise OperationError(space.w_TypeError, 
+                      space.wrap('Not implemented for this type'))
         calc_dtype = find_unaryop_result_dtype(space,
                                   w_obj.get_dtype(),
                                   promote_to_float=self.promote_to_float,
@@ -301,6 +307,10 @@
             w_out = None
         w_lhs = convert_to_array(space, w_lhs)
         w_rhs = convert_to_array(space, w_rhs)
+        if w_lhs.get_dtype().is_flexible_type() or \
+           w_rhs.get_dtype().is_flexible_type():
+            raise OperationError(space.w_TypeError, 
+                      space.wrap('unsupported operand types'))
         calc_dtype = find_binop_result_dtype(space,
             w_lhs.get_dtype(), w_rhs.get_dtype(),
             int_only=self.int_only,
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
@@ -2249,18 +2249,30 @@
     def test_stringarray(self):
         from _numpypy import array
         a = array(['abc'],'S3')
-        assert repr(a) == "array(['abc'])"
         assert str(a.dtype) == '|S3'
         a = array(['abc'])
-        assert repr(a) == "array(['abc'])"
         assert str(a.dtype) == '|S3'
         a = array(['abc','defg','ab'])
         assert str(a.dtype) == '|S4'
         assert a[0] == 'abc'
         assert a[1] == 'defg'
         assert a[2] == 'ab'
-        assert repr(a) == "array(['abc', 'defg', 'ab'])"
+        raises(TypeError, a, 'sum')
+        raises(TypeError, 'a+a')
 
+    def test_flexible_repr(self):
+        # import overrides str(), repr() for array
+        from numpypy.core import arrayprint
+        from _numpypy import array
+        a = array(['abc'],'S3')
+        s = repr(a)
+        # simplify \n in repr
+        assert s.replace('\n', '') == "array(['abc'],       dtype='|S3')"
+        a = array(['abc','defg','ab'])
+        s = repr(a)
+        assert s.replace('\n', '') == \
+                      "array(['abc', 'defg', 'ab'],       dtype='|S4')"
+         
        
 class AppTestPyPy(BaseNumpyAppTest):
     def setup_class(cls):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to