From e1a3854f2a4ce44ea14a66796a0a53ca57f2b537 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 20 May 2016 20:10:29 +0200 Subject: [PATCH] utils: add special serializer for numpy.int64 (#492) It looks like COUNT(*) returns a numpy.int64 value that the default JSONEncoder does not handle. While at if we get a type we are not handling make it easier to debug the issue by throwing a TypeError exception with useful data. Fix #486 --- caravel/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/caravel/utils.py b/caravel/utils.py index 7e3d4c079f500..5f2a76009204e 100644 --- a/caravel/utils.py +++ b/caravel/utils.py @@ -7,6 +7,7 @@ import functools import json import logging +import numpy from datetime import datetime import parsedatetime @@ -221,6 +222,12 @@ def json_iso_dttm_ser(obj): """ if isinstance(obj, datetime): obj = obj.isoformat() + elif isinstance(obj, numpy.int64): + obj = int(obj) + else: + raise TypeError( + "Unserializable object {} of type {}".format(obj, type(obj)) + ) return obj