[pypy-commit] pypy default: test, fix scalar string types

mattip noreply at buildbot.pypy.org
Mon Feb 11 23:44:37 CET 2013


Author: mattip <matti.picus at gmail.com>
Branch: 
Changeset: r61106:21844583c8a0
Date: 2013-02-12 00:28 +0200
http://bitbucket.org/pypy/pypy/changeset/21844583c8a0/

Log:	test, fix scalar string types

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
@@ -224,7 +224,7 @@
             size = int(name[1:])
         except ValueError:
             raise OperationError(space.w_TypeError, space.wrap("data type not understood"))
-    if char == 'S':
+    if char == 'S' or char == 'c':
         itemtype = types.StringType(size)
         basename = 'string'
         num = 18
@@ -264,8 +264,10 @@
             return cache.dtypes_by_name[name]
         except KeyError:
             pass
-        if name[0] in 'VSU' or name[0] in '<>=' and name[1] in 'VSU':
+        if name[0] in 'VSUc' or name[0] in '<>=' and name[1] in 'VSUc':
             return variable_dtype(space, name)
+        raise OperationError(space.w_TypeError, space.wrap(
+                       "data type %s not understood" % name))
     elif space.isinstance_w(w_dtype, space.w_list):
         return dtype_from_list(space, w_dtype)
     elif space.isinstance_w(w_dtype, space.w_dict):
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -891,8 +891,9 @@
 @unwrap_spec(ndmin=int, copy=bool, subok=bool)
 def array(space, w_object, w_dtype=None, copy=True, w_order=None, subok=False,
           ndmin=0):
-    if not issequence_w(space, w_object):
-        if space.is_none(w_dtype):
+    isstr = space.isinstance_w(w_object, space.w_str)
+    if not issequence_w(space, w_object) or isstr:
+        if space.is_none(w_dtype) or isstr:
             w_dtype = interp_ufuncs.find_dtype_for_scalar(space, w_object)
         dtype = space.interp_w(interp_dtype.W_Dtype,
           space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
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
@@ -324,10 +324,12 @@
             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'))
+        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 dtypes %s and %s for "%s"' % \
+                 (w_rhs.get_dtype().get_name(), w_lhs.get_dtype().get_name(),
+                  self.name)))
         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
@@ -2561,6 +2561,12 @@
         from _numpypy import array
         a = array('ffff')
         assert a.shape == ()
+        a = array('x', dtype='>S')
+        assert str(a.dtype) == '|S1'
+        a = array('x', dtype='c')
+        assert str(a.dtype) == '|S1'
+        # XXX can sort flexible types, why not comparison?
+        #assert a == 'x'
 
     def test_flexible_repr(self):
         # numpypy overrides _numpypy repr with pure python one


More information about the pypy-commit mailing list