[pypy-commit] pypy default: fix numpy dtype name attribute
bdkearns
noreply at buildbot.pypy.org
Fri May 2 08:03:05 CEST 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r71183:0f75ad4d14ce
Date: 2014-05-02 01:00 -0400
http://bitbucket.org/pypy/pypy/changeset/0f75ad4d14ce/
Log: fix numpy dtype name attribute
diff --git a/pypy/module/micronumpy/descriptor.py b/pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/descriptor.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -131,12 +131,13 @@
return dtype
def get_name(self):
- return self.w_box_type.name
+ name = self.w_box_type.name
+ if name.endswith('_'):
+ name = name[:-1]
+ return name
def descr_get_name(self, space):
name = self.get_name()
- if name[-1] == '_':
- name = name[:-1]
if self.is_flexible() and self.elsize != 0:
return space.wrap(name + str(self.elsize * 8))
return space.wrap(name)
@@ -819,7 +820,7 @@
w_box_type=space.gettypefor(boxes.W_ULongBox),
)
aliases = {
- NPY.BOOL: ['bool', 'bool8'],
+ NPY.BOOL: ['bool_', 'bool8'],
NPY.BYTE: ['byte'],
NPY.UBYTE: ['ubyte'],
NPY.SHORT: ['short'],
@@ -834,8 +835,8 @@
NPY.CFLOAT: ['csingle'],
NPY.CDOUBLE: ['complex', 'cfloat', 'cdouble'],
NPY.CLONGDOUBLE: ['clongdouble', 'clongfloat'],
- NPY.STRING: ['string', 'str'],
- NPY.UNICODE: ['unicode'],
+ NPY.STRING: ['string_', 'str'],
+ NPY.UNICODE: ['unicode_'],
}
self.alternate_constructors = {
NPY.BOOL: [space.w_bool],
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
@@ -47,6 +47,7 @@
assert d.kind == 'b'
assert dtype(d) is d
assert dtype('bool') is d
+ assert dtype('bool_') is d
assert dtype('|b1') is d
b = '>' if sys.byteorder == 'little' else '<'
assert dtype(b + 'i4') is not dtype(b + 'i4')
@@ -63,10 +64,12 @@
assert dtype(int).names is None
assert dtype(int).hasobject is False
assert dtype(int).subdtype is None
+ assert dtype(str) is dtype('string') is dtype('string_')
+ assert dtype(unicode) is dtype('unicode') is dtype('unicode_')
assert dtype(None) is dtype(float)
- for d in [dtype('<c8'), dtype('>i4')]:
+ for d in [dtype('<c8'), dtype('>i4'), dtype('bool')]:
for key in ["d[2]", "d['z']", "d[None]"]:
exc = raises(KeyError, key)
assert exc.value[0] == "There are no fields in dtype %s." % str(d)
More information about the pypy-commit
mailing list