From 11807d66ff7483031b3258bb7168d71d917651f8 Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Tue, 29 Apr 2014 10:12:30 +0200 Subject: [PATCH] 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. --- timeside/analyzer/core.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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) -- 2.39.5