]> git.parisson.com Git - timeside.git/commitdiff
Another solution to fix container json serializer to return non numpyarray data
authorThomas Fillon <thomas@parisson.com>
Tue, 29 Apr 2014 08:12:30 +0000 (10:12 +0200)
committerThomas Fillon <thomas@parisson.com>
Tue, 29 Apr 2014 08:12:30 +0000 (10:12 +0200)
This commit follow and ammend 3d42e56d0da85a1e1 .
The JSON serializer will handle simple numpy data type as number and boolean and will simply convert them to native python type. For such type there is no need to preserve the numpy dtype like it is the case with numpy arrays.

timeside/analyzer/core.py

index f2a2548809d6e46145d4901c47726d09d7c43b55..07eff5453aa23ac8273239bfe1af70d0aad356bb 100644 (file)
@@ -935,7 +935,12 @@ class AnalyzerResultContainer(dict):
             if isinstance(obj, numpy.ndarray):
                 return {'numpyArray': obj.tolist(),
                         'dtype': obj.dtype.__str__()}
-            raise TypeError(repr(obj) + " is not JSON serializable")
+            elif isinstance(obj, numpy.generic):
+                return numpy.asscalar(obj)
+            else:
+                print obj
+                print type(obj)
+                raise TypeError(repr(obj) + " is not JSON serializable")
 
         json_str = json.dumps([res.as_dict() for res in self.values()],
                               default=NumpyArrayEncoder)