Skip to content

TypeError: can't serialize np.float32(1213771) or np.int64(1213771) #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dragoljub opened this issue Oct 14, 2015 · 1 comment
Closed

Comments

@dragoljub
Copy link

I found these strange corner cases when serializing np.float32 and np.int64 values. What's strange is that np.int32 and np.float64 for the same underlying value works.

Any ideas whats going on? ❓

import msgpack
import numpy as np

In [1]: np.__version__

Out[1]: '1.9.2'

In [2]: msgpack.version

Out[2]: (0, 4, 6)

In [3]: msgpack.packb([np.float32(1213771)])

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-a34bd885d43f> in <module>()
----> 1 msgpack.packb([np.float32(1213771)])

D:\Python27\lib\site-packages\msgpack\__init__.pyc in packb(o, **kwargs)
     45     See :class:`Packer` for options.
     46     """
---> 47     return Packer(**kwargs).pack(o)
     48 
     49 # alias for compatibility to simplejson/marshal/pickle.

msgpack\_packer.pyx in msgpack._packer.Packer.pack (msgpack\_packer.cpp:223)()

msgpack\_packer.pyx in msgpack._packer.Packer.pack (msgpack\_packer.cpp:225)()

msgpack\_packer.pyx in msgpack._packer.Packer._pack (msgpack\_packer.cpp:213)()

msgpack\_packer.pyx in msgpack._packer.Packer._pack (msgpack\_packer.cpp:220)()

TypeError: can't serialize 1213771.0

In [4]: msgpack.packb([np.int64(1213771)])

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-dc4780e7a01d> in <module>()
----> 1 msgpack.packb([np.int64(1213771)])

D:\Python27\lib\site-packages\msgpack\__init__.pyc in packb(o, **kwargs)
     45     See :class:`Packer` for options.
     46     """
---> 47     return Packer(**kwargs).pack(o)
     48 
     49 # alias for compatibility to simplejson/marshal/pickle.

msgpack\_packer.pyx in msgpack._packer.Packer.pack (msgpack\_packer.cpp:223)()

msgpack\_packer.pyx in msgpack._packer.Packer.pack (msgpack\_packer.cpp:225)()

msgpack\_packer.pyx in msgpack._packer.Packer._pack (msgpack\_packer.cpp:213)()

msgpack\_packer.pyx in msgpack._packer.Packer._pack (msgpack\_packer.cpp:220)()

TypeError: can't serialize 1213771

In [5]: msgpack.packb([np.int32(1213771)])

Out[5]: '\x91\xce\x00\x12\x85K'

In [6]: msgpack.packb([np.float64(1213771)])

Out[6]: '\x91\xcbA2\x85K\x00\x00\x00\x00'
@methane
Copy link
Member

methane commented Oct 14, 2015

See #61.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants