Author: Romain Guillebert <[email protected]>
Branch: numpy-pickle
Changeset: r64171:8b807472067a
Date: 2013-05-15 16:56 +0200
http://bitbucket.org/pypy/pypy/changeset/8b807472067a/
Log: Add some tests for subarrays, fix itemsize
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,7 @@
if w_fields == space.w_None:
self.fields = None
else:
+ self.fields = {}
ofs_and_items = []
size = 0
for key in space.listview(w_fields):
@@ -330,8 +331,9 @@
elif char == 'V':
num = 20
basename = 'void'
- w_box_type = space.gettypefor(interp_boxes.W_VoidBox)
- return dtype_from_list(space, space.newlist([]))
+ itemtype = types.VoidType(size)
+ return W_Dtype(itemtype, 20, VOIDLTR, "void" + str(size),
+ "V", space.gettypefor(interp_boxes.W_VoidBox))
else:
assert char == 'U'
basename = 'unicode'
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
@@ -278,17 +278,6 @@
assert a.dtype.__reduce__() == (dtype, ('i8', 0, 1), (3, '<', None,
None, None, -1, -1, 0))
assert loads(dumps(a.dtype)) == a.dtype
- def test_pickle_record(self):
- from numpypy import array, dtype
- from cPickle import loads, dumps
-
- d = dtype([("x", "int32"), ("y", "int32"), ("z", "int32"), ("value",
float)])
- assert d.__reduce__() == (dtype, ('V20', 0, 1), (3, '<', None, ('x',
'y', 'z', 'value'), {'y': (dtype('int32'), 4), 'x': (dtype('int32'), 0), 'z':
(dtype('int32'), 8), 'value': (dtype('float64'), 12)}, 20, 1, 0))
-
- new_d = loads(dumps(d))
-
- assert new_d.__reduce__() == d.__reduce__()
-
class AppTestTypes(BaseAppTestDtypes):
def test_abstract_types(self):
import numpypy as numpy
@@ -766,6 +755,7 @@
assert isinstance(unicode_(3), unicode)
class AppTestRecordDtypes(BaseNumpyAppTest):
+ spaceconfig = dict(usemodules=["micronumpy", "struct", "binascii"])
def test_create(self):
from numpypy import dtype, void
@@ -810,6 +800,30 @@
assert dt.fields == None
assert dt.subdtype == (dtype("float64"), (10,))
+ def test_pickle_record(self):
+ from numpypy import array, dtype
+ from cPickle import loads, dumps
+
+ d = dtype([("x", "int32"), ("y", "int32"), ("z", "int32"), ("value",
float)])
+ assert d.__reduce__() == (dtype, ('V20', 0, 1), (3, '<', None, ('x',
'y', 'z', 'value'), {'y': (dtype('int32'), 4), 'x': (dtype('int32'), 0), 'z':
(dtype('int32'), 8), 'value': (dtype('float64'), 12)}, 20, 1, 0))
+
+ new_d = loads(dumps(d))
+
+ assert new_d.__reduce__() == d.__reduce__()
+
+ def test_pickle_record_subarrays(self):
+ from numpypy import array, dtype
+ from cPickle import loads, dumps
+
+ d = dtype([("x", "int32", (3,)), ("y", "int32", (2,)), ("z", "int32",
(4,)), ("value", float, (5,))])
+ new_d = loads(dumps(d))
+
+ keys = d.fields.keys()
+ keys.sort()
+ assert keys == ["value", "x", "y", "z"]
+
+ assert new_d.itemsize == d.itemsize == 76
+
class AppTestNotDirect(BaseNumpyAppTest):
def setup_class(cls):
BaseNumpyAppTest.setup_class.im_func(cls)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit