Closed
Description
Numpy integers operate almost exactly like Python integers in all circumstances, but msgpack doesn't handle them. That's fine, but the error message that gets thrown is fairly confusing.
>>> import numpy
>>> five = numpy.int32(5)
>>> five
5
>>> type(five)
<type 'numpy.int32'>
>>> msgpack.dumps(five)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_msgpack.pyx", line 151, in msgpack._msgpack.packb (msgpack/_msgpack.c:1607)
File "_msgpack.pyx", line 135, in msgpack._msgpack.Packer.pack (msgpack/_msgpack.c:1363)
File "_msgpack.pyx", line 130, in msgpack._msgpack.Packer._pack (msgpack/_msgpack.c:1305)
TypeError: can't serialize 5
It's not really msgpack's problem per se, but I think handling it more gracefully would be nice, since numpy is in very widespread use. I'd suggest adding type information to the TypeError, so the error message would read something like:
TypeError: can't serialize 5 (<type 'numpy.int32'>)
That's make debugging this and other similar problems easier.
Actually treating numpy integers (and other numpy scalar types) as integers would be a bonus.
Please note:
I wasn't the initial reporter of this bug/request. I am simple re-posting this (msgpack/msgpack#36 (comment)) into this repo.
Metadata
Metadata
Assignees
Labels
No labels