lebedov / msgpack-numpy

Serialize numpy arrays using msgpack
Other
197 stars 33 forks source link

Make default and object_hook default params consistent with msgpack #23

Closed tiagocoutinho closed 6 years ago

tiagocoutinho commented 6 years ago

After using msgpack_numpy 0.4.2 to patch msgpack, when I pass my custom default/object_hook to msgpack.pack(b)/msgpack.unpack(b) I loose the ability to pack/unpack numpy.

Example:

import pickle
import numpy
import msgpack
import msgpack_numpy
msgpack_numpy.patch()

def encode_pickle(obj):
    return dict(__pickle__=1, as_str=pickle.dumps(obj))

data = numpy.arange(10)

# this works, obviously:
msgpack.packb(data)

# this raises TypeError: can't serialize array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
msgpack.packb(data, default=encode_pickle)

This PR proposes to fix that.

lebedov commented 6 years ago

Many of the unit tests appear to be broken by your PR. Can you please fix?

tiagocoutinho commented 6 years ago

Yes, of course. Sorry for that. It should be ok now.

lebedov commented 6 years ago

Thanks!