From: Thomas Fillon Date: Tue, 29 Apr 2014 08:12:30 +0000 (+0200) Subject: Another solution to fix container json serializer to return non numpyarray data X-Git-Tag: 0.5.5~1^2~38^2 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=11807d66ff7483031b3258bb7168d71d917651f8;p=timeside.git Another solution to fix container json serializer to return non numpyarray data 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. --- diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index f2a2548..07eff54 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -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)