[pypy-commit] pypy dtypes-compatability: use, fix title in monkeypatched _usefields; add test_bad_param
mattip
noreply at buildbot.pypy.org
Sun Jul 12 22:12:21 CEST 2015
Author: mattip <matti.picus at gmail.com>
Branch: dtypes-compatability
Changeset: r78534:6caae7e7edd6
Date: 2015-07-10 15:28 +0300
http://bitbucket.org/pypy/pypy/changeset/6caae7e7edd6/
Log: use, fix title in monkeypatched _usefields; add test_bad_param
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
@@ -643,7 +643,10 @@
if space.isinstance_w(w_fldname, space.w_tuple):
fldlist = space.listview(w_fldname)
fldnames[i] = space.str_w(fldlist[0])
- titles[i] = space.str_w(fldlist[1])
+ if space.is_w(fldlist[1], space.w_None):
+ titles[i] = None
+ else:
+ titles[i] = space.str_w(fldlist[1])
if len(fldlist) != 2:
raise oefmt(space.w_TypeError, "data type not understood")
elif space.isinstance_w(w_fldname, space.w_str):
@@ -722,15 +725,14 @@
alignment = -1
format = dtype_from_spec(space, obj[0], alignment=alignment)
if len(obj) > 2:
- title = obj[2]
+ title = space.wrap(obj[2])
else:
- title = None
- allfields.append((fname, format, num, title))
+ title = space.w_None
+ allfields.append((space.wrap(fname), format, num, title))
allfields.sort(key=lambda x: x[2])
- names = [x[0] for x in allfields]
+ names = [space.newtuple([x[0], x[3]]) for x in allfields]
formats = [x[1] for x in allfields]
offsets = [x[2] for x in allfields]
- titles = [x[3] for x in allfields]
aslist = []
if align:
alignment = 0
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
@@ -1307,7 +1307,7 @@
'formats':['i4', 'u1'],
'offsets':[0, 4]}, align=True)
assert dt.itemsize == 8
- dt = np.dtype([('f0', 'i4'), ('f1', 'u1')], align=True)
+ dt = np.dtype({'f0': ('i4', 0), 'f1':('u1', 4)}, align=True)
assert dt.itemsize == 8
assert dt.alignment == 4
assert str(dt) == "{'names':['f0','f1'], 'formats':['<i4','u1'], 'offsets':[0,4], 'itemsize':8, 'aligned':True}"
@@ -1357,6 +1357,27 @@
assert dt1 == dt2
assert dt2 == dt3
+ def test_bad_param(self):
+ import numpy as np
+ # Can't give a size that's too small
+ raises(ValueError, np.dtype,
+ {'names':['f0', 'f1'],
+ 'formats':['i4', 'i1'],
+ 'offsets':[0, 4],
+ 'itemsize':4})
+ # If alignment is enabled, the alignment (4) must divide the itemsize
+ raises(ValueError, np.dtype,
+ {'names':['f0', 'f1'],
+ 'formats':['i4', 'i1'],
+ 'offsets':[0, 4],
+ 'itemsize':9}, align=True)
+ # If alignment is enabled, the individual fields must be aligned
+ raises(ValueError, np.dtype,
+ {'names':['f0', 'f1'],
+ 'formats':['i1', 'f4'],
+ 'offsets':[0, 2]}, align=True)
+
+
class AppTestNotDirect(BaseNumpyAppTest):
def setup_class(cls):
More information about the pypy-commit
mailing list