Repository: ipython/ipython

Issue:
ipython parallel pushing and pulling recarrays
There's a problem with pushing and pulling recarrays as they completely loose the type. A mininum working example can be seen here. I can also post to the mailing list if that helps.

Cheers
   Wolfgang



Discussion:
I think you left out the example.

yes stupid me https://gist.github.com/2986286

btw this a simple local cluster , no ssh nothing fancy


Resolving patch:
diff --git a/IPython/utils/newserialized.py b/IPython/utils/newserialized.py
--- a/IPython/utils/newserialized.py
+++ b/IPython/utils/newserialized.py
@@ -110,7 +110,7 @@ def __init__(self, unSerialized):
                 self.obj = numpy.ascontiguousarray(self.obj, dtype=None)
                 self.typeDescriptor = 'ndarray'
                 self.metadata = {'shape':self.obj.shape,
-                                 'dtype':self.obj.dtype.str}
+                                 'dtype':self.obj.dtype}
         elif isinstance(self.obj, bytes):
             self.typeDescriptor = 'bytes'
             self.metadata = {}


Test patch:
diff --git a/IPython/parallel/tests/test_newserialized.py b/IPython/parallel/tests/test_newserialized.py
--- a/IPython/parallel/tests/test_newserialized.py
+++ b/IPython/parallel/tests/test_newserialized.py
@@ -90,14 +90,14 @@ def test_ndarray_serialized(self):
         self.assertEquals(td, 'ndarray')
         md = ser1.getMetadata()
         self.assertEquals(md['shape'], a.shape)
-        self.assertEquals(md['dtype'], a.dtype.str)
+        self.assertEquals(md['dtype'], a.dtype)
         buff = ser1.getData()
         self.assertEquals(buff, buffer(a))
         s = ns.Serialized(buff, td, md)
         final = ns.unserialize(s)
         self.assertEquals(buffer(a), buffer(final))
         self.assertTrue((a==final).all())
-        self.assertEquals(a.dtype.str, final.dtype.str)
+        self.assertEquals(a.dtype, final.dtype)
         self.assertEquals(a.shape, final.shape)
         # test non-copying:
         a[2] = 1e9
diff --git a/IPython/parallel/tests/test_view.py b/IPython/parallel/tests/test_view.py
--- a/IPython/parallel/tests/test_view.py
+++ b/IPython/parallel/tests/test_view.py
@@ -275,6 +275,30 @@ def test_apply_numpy(self):
             C = view.apply_sync(lambda x:x, B)
             assert_array_equal(B,C)
     
+    @skip_without('numpy')
+    def test_push_pull_recarray(self):
+        """push/pull recarrays"""
+        import numpy
+        from numpy.testing.utils import assert_array_equal
+        
+        view = self.client[-1]
+        
+        R = numpy.array([
+            (1, 'hi', 0.),
+            (2**30, 'there', 2.5),
+            (-99999, 'world', -12345.6789),
+        ], [('n', int), ('s', '|S10'), ('f', float)])
+        
+        view['RR'] = R
+        R2 = view['RR']
+        
+        r_dtype, r_shape = view.apply_sync(interactive(lambda : (RR.dtype, RR.shape)))
+        self.assertEquals(r_dtype, R.dtype)
+        self.assertEquals(r_shape, R.shape)
+        self.assertEquals(R2.dtype, R.dtype)
+        self.assertEquals(R2.shape, R.shape)
+        assert_array_equal(R2, R)
+    
     def test_map(self):
         view = self.client[:]
         def f(x):