mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
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
This commit is contained in:
parent
7630d73002
commit
e1a3854f2a
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
||||
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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user