##// END OF EJS Templates
pickle arrays with dtype=object...
MinRK -
Show More
@@ -287,6 +287,21 b' class TestView(ClusterTestCase):'
287 assert_array_equal(B,C)
287 assert_array_equal(B,C)
288
288
289 @skip_without('numpy')
289 @skip_without('numpy')
290 def test_apply_numpy_object_dtype(self):
291 """view.apply(f, ndarray) with dtype=object"""
292 import numpy
293 from numpy.testing.utils import assert_array_equal
294 view = self.client[-1]
295
296 A = numpy.array([dict(a=5)])
297 B = view.apply_sync(lambda x:x, A)
298 assert_array_equal(A,B)
299
300 A = numpy.array([(0, dict(b=10))], dtype=[('i', int), ('o', object)])
301 B = view.apply_sync(lambda x:x, A)
302 assert_array_equal(A,B)
303
304 @skip_without('numpy')
290 def test_push_pull_recarray(self):
305 def test_push_pull_recarray(self):
291 """push/pull recarrays"""
306 """push/pull recarrays"""
292 import numpy
307 import numpy
@@ -192,7 +192,15 b' class CannedArray(CannedObject):'
192 from numpy import ascontiguousarray
192 from numpy import ascontiguousarray
193 self.shape = obj.shape
193 self.shape = obj.shape
194 self.dtype = obj.dtype.descr if obj.dtype.fields else obj.dtype.str
194 self.dtype = obj.dtype.descr if obj.dtype.fields else obj.dtype.str
195 self.pickled = False
195 if sum(obj.shape) == 0:
196 if sum(obj.shape) == 0:
197 self.pickled = True
198 elif obj.dtype == 'O':
199 # can't handle object dtype with buffer approach
200 self.pickled = True
201 elif obj.dtype.fields and any(dt == 'O' for dt,sz in obj.dtype.fields.values()):
202 self.pickled = True
203 if self.pickled:
196 # just pickle it
204 # just pickle it
197 self.buffers = [pickle.dumps(obj, -1)]
205 self.buffers = [pickle.dumps(obj, -1)]
198 else:
206 else:
@@ -203,7 +211,7 b' class CannedArray(CannedObject):'
203 def get_object(self, g=None):
211 def get_object(self, g=None):
204 from numpy import frombuffer
212 from numpy import frombuffer
205 data = self.buffers[0]
213 data = self.buffers[0]
206 if sum(self.shape) == 0:
214 if self.pickled:
207 # no shape, we just pickled it
215 # no shape, we just pickled it
208 return pickle.loads(data)
216 return pickle.loads(data)
209 else:
217 else:
General Comments 0
You need to be logged in to leave comments. Login now