[issue24313] json fails to serialise numpy.int64

Serhiy Storchaka report at bugs.python.org
Fri May 29 07:46:35 CEST 2015


Serhiy Storchaka added the comment:

Yes, it looks as a bug (or rather lack of feature) in numpy, but numpy have no chance to fix it without help from Python. The json module is not flexible enough.

For now this issue can be workarounded only from user side, with special default handler.

>>> import numpy, json
>>> def default(o):
...     if isinstance(o, numpy.integer): return int(o)
...     raise TypeError
... 
>>> json.dumps({'value': numpy.int64(42)}, default=default)
'{"value": 42}'

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24313>
_______________________________________


More information about the Python-bugs-list mailing list