Author: Brian Kearns <[email protected]>
Branch:
Changeset: r69325:00beb1b741ed
Date: 2014-02-23 20:52 -0500
http://bitbucket.org/pypy/pypy/changeset/00beb1b741ed/
Log: fix some dtype str/repr cases
diff --git a/pypy/module/micronumpy/arrayimpl/sort.py
b/pypy/module/micronumpy/arrayimpl/sort.py
--- a/pypy/module/micronumpy/arrayimpl/sort.py
+++ b/pypy/module/micronumpy/arrayimpl/sort.py
@@ -10,7 +10,7 @@
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib.rarithmetic import widen
from rpython.rlib.objectmodel import specialize
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
from pypy.module.micronumpy.base import W_NDimArray
from pypy.module.micronumpy import interp_dtype, types
from pypy.module.micronumpy.iter import AxisIterator
@@ -175,9 +175,9 @@
return cache._lookup(tp)(arr, space, w_axis,
itemtype.get_element_size())
# XXX this should probably be changed
- raise OperationError(space.w_NotImplementedError,
- space.wrap("sorting of non-numeric types " + \
- "'%s' is not implemented" % arr.dtype.get_name(), ))
+ raise oefmt(space.w_NotImplementedError,
+ "sorting of non-numeric types '%s' is not implemented",
+ arr.dtype.name)
all_types = (types.all_float_types + types.all_complex_types +
types.all_int_types)
@@ -318,9 +318,9 @@
return cache._lookup(tp)(arr, space, w_axis,
itemtype.get_element_size())
# XXX this should probably be changed
- raise OperationError(space.w_NotImplementedError,
- space.wrap("sorting of non-numeric types " + \
- "'%s' is not implemented" % arr.dtype.get_name(), ))
+ raise oefmt(space.w_NotImplementedError,
+ "sorting of non-numeric types '%s' is not implemented",
+ arr.dtype.name)
all_types = (types.all_float_types + types.all_complex_types +
types.all_int_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
@@ -119,21 +119,30 @@
def get_size(self):
return self.size * self.itemtype.get_element_size()
- def get_name(self):
- if self.char == 'S':
- return '|S' + str(self.get_size())
- return self.name
-
def get_float_dtype(self, space):
assert self.kind == NPY.COMPLEXLTR
assert self.float_type is not None
return get_dtype_cache(space).dtypes_by_name[self.byteorder +
self.float_type]
def descr_str(self, space):
- return space.wrap(self.get_name())
+ if not self.is_record_type():
+ if self.char == 'S':
+ s = '|S' + str(self.get_size())
+ else:
+ s = self.name
+ return space.wrap(s)
+ return space.str(self.descr_get_descr(space))
def descr_repr(self, space):
- return space.wrap("dtype('%s')" % self.get_name())
+ if not self.is_record_type():
+ if self.char == 'S':
+ s = 'S' + str(self.get_size())
+ else:
+ s = self.name
+ r = space.wrap(s)
+ else:
+ r = self.descr_get_descr(space)
+ return space.wrap("dtype(%s)" % space.str_w(space.repr(r)))
def descr_get_itemsize(self, space):
return space.wrap(self.get_size())
diff --git a/pypy/module/micronumpy/test/test_dtypes.py
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -160,6 +160,12 @@
d = dtype('?')
assert repr(d) == "dtype('bool')"
assert str(d) == "bool"
+ d = dtype([('', '<f8')])
+ assert repr(d) == "dtype([('f0', '<f8')])"
+ assert str(d) == "[('f0', '<f8')]"
+ d = dtype('S5')
+ assert repr(d) == "dtype('S5')"
+ assert str(d) == "|S5"
def test_bool_array(self):
from numpypy import array, False_, True_
@@ -848,6 +854,7 @@
assert dtype('unicode').str == byteorder + 'U0'
assert dtype(('string', 7)).str == '|S7'
assert dtype(('unicode', 7)).str == '<U7'
+ assert dtype([('', 'f8')]).str == "|V8"
def test_intp(self):
from numpypy import dtype
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit