Error when de-serializing dictionary containing numpy arrays
Closed this issue · 1 comments
e0en commented
The code below causes error:
import numpy as np
import msgpack
import msgpack_numpy as m
m.patch()
dict_np = {"np": np.zeros((3, 4)), }
packed = msgpack.packb(dict_np)
unpacked = msgpack.unpackb(packed) # this will cause error
The code above will cause a KeyError
because the decode
function in msgpack_numpy
tries to decode the dictionary dict_np
as a serialized version of numpy array.
Wrapping the entire content of decode
function with try-except clause will solve this issue. More specifically, modify the code below:
def decode(obj):
blah_blah
like this:
def decode(obj):
try:
blah_blah
except KeyError:
return obj
lebedov commented
Fixed in Github.