lebedov / msgpack-numpy

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

Problem with unpacking packed multi-dimensional array #56

Open Bomsw opened 1 month ago

Bomsw commented 1 month ago

I've been trying to use the package to work with some multi-dimensional numpy arrays, unfortunately it does not seem to work

>>> import numpy as np
>>> import msgpack_numpy
>>> packed = msgpack_numpy.packb(np.ones((3,3)))
>>> msgpack_numpy.unpackb(packed)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/msgpack_numpy.py", line 287, in unpackb
    return _unpackb(packed, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/msgpack/fallback.py", line 121, in unpackb
    ret = unpacker._unpack()
  File "/usr/local/lib/python3.9/dist-packages/msgpack/fallback.py", line 602, in _unpack
    ret = self._object_hook(ret)
  File "/usr/local/lib/python3.9/dist-packages/msgpack_numpy.py", line 103, in decode
    return np.ndarray(buffer=obj[b'data'],
TypeError: buffer is too small for requested array

I am using numpy 1.24.4, msgpack-numpy 0.4.8 and msgpack 0.5.6 on python 3.9.5

lebedov commented 1 month ago

I can't seem to reproduce this:

❯ pip freeze | egrep '(msgpack-numpy|msgpack-python|numpy)'
msgpack-numpy==0.4.8
msgpack-python==0.5.6
numpy==1.24.4
❯ python --version
Python 3.9.5
❯ python -c 'import msgpack_numpy, numpy; x=numpy.ones((3,3)); s=msgpack_numpy.packb(x); print(msgpack_numpy.unpackb(s))'
[[1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]]

Can you try reinstalling all of the packages (msgpack-python, numpy, msgpack-numpy) from scratch?