lebedov/msgpack-numpy

Defaults differs from `msgpack`

Closed this issue · 2 comments

msgpack-numpy defaults differs from msgpack:

>>> import msgpack
>>> import msgpack_numpy as m
>>> msgpack.unpackb(msgpack.packb("foo"))
b'foo'
>>> m.patch()
>>> msgpack.unpackb(msgpack.packb("foo"))
'foo'
>>> 

I like that the default is changed. The msgpack default behaviour messes up dictionary keys and other things which is annoying.
However I did find that the behaviour between m.patch() and instead specifying the defaults differs.

In [5]: x_enc = msgpack.packb("foo", default=m.encode)

In [6]: x_dec = msgpack.unpackb(x_enc, object_hook=m.decode)

In [7]: x_dec

Out[7]: b'foo'

which threw me off.

I agree that the encoding/decoding parameters should be consistent with those of msgpack-python 0.4.*, specifically with respect to string and binary types. Updated default behavior in the latest revision; you can obtain the old behavior using

x_enc = msgpack_numpy.packb('foo', use_bin_type=True)
x_dec = msgpack_numpy.unpackb(x_enc, encoding='utf-8') # should return str on both Py2 and Py3