lebedov / msgpack-numpy

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

Re-encoding a numpy ndarray returns a 'dict' #13

Closed tvkpz closed 8 years ago

tvkpz commented 8 years ago

Using msgpack-numpy for the first time. I tried the example but it returns a 'dict'. How do I get back the original numpy ndarray from the 'data' field.

Sorry if this is not the right forum for asking the question.

lebedov commented 8 years ago

As per the example in the README, you should be encoding data by calling msgpack_numpy.packb; this will return the serialized string rather than the dict. You can decode the string with msgpack_numpy.unpackb. Feel free to reopen the issue if this doesn't answer your question.

tvkpz commented 8 years ago

In the example, the type of x_rec after unpacking is 'dict', which is not the same as 'x'. So my question was how can I get back x.

Thank you!

lebedov commented 8 years ago

That's strange - the value returned by unpackb in this case should be an ndarray, not a dict. What versions of Python, msgpack-python, and msgpack-numpy are you using?

tvkpz commented 8 years ago

Python 3.5 msgpack-python==0.4.7 msgpack-numpy==0.3.7

lebedov commented 8 years ago

Looks like a Python 3 bug - just uploaded a fix. Try the latest revision from GitHub.

tvkpz commented 8 years ago

Thanks! Problem is fixed. BTW may I know what exactly you changed.

lebedov commented 8 years ago

Sure. b'foo' == 'foo' is True in Python 2 but False in Python 3. Since part of msgpack-numpy relied upon the former assumption, it broke in Python 3.

subiol commented 7 years ago

I am hitting this error after I installed msgpack-numpy using pip. Pip has version 0.3.7 of this library which was uploaded on 2016-03-13, so that is why I am probably getting this bug.

@lebedov if you are in charge of the pip package, could you actualize to the last version?

lebedov commented 7 years ago

@subiol: sure, done.