-
Notifications
You must be signed in to change notification settings - Fork 225
Improve handling of numpy integers #61
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
Comments
That's strange, because msgpack uses Its unsigned integer types do not inherit from Python types, but -- together with its signed and long types -- inherit from Numpy's Since these are all underlyingly stored as C types, perhaps it's more sensible to just special-case a check for a numpy number and do the packing in C? The same error occurs for bools: >>> msgpack.packb(numpy.array([True])[0])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_packer.pyx", line 259, in msgpack._packer.packb (msgpack/_packer.cpp:259)
File "_packer.pyx", line 184, in msgpack._packer.Packer.pack (msgpack/_packer.cpp:184)
File "_packer.pyx", line 179, in msgpack._packer.Packer._pack (msgpack/_packer.cpp:179)
TypeError: can't serialize True Here msgpack-python uses Strings and dicts also seem to pack fine. |
This is a more generic issue with msppack not handling numpy data types, is it not? For example I get this issue for numpy.float32's and other dtypes as well. Anyone working on a fix for this? If not maybe I can. |
msgpack-python now have ext type. |
So is the BKM to convert to native python types? Its there a reason that np.float64 and np.int32 serialize just fine while np.float32 and np.int64? 😕 |
There are no intention. |
Numpy integers operate almost exactly like Python integers in all circumstances, but msgpack doesn't handle them. That's fine, but the error message that gets thrown is fairly confusing.
It's not really msgpack's problem per se, but I think handling it more gracefully would be nice, since numpy is in very widespread use. I'd suggest adding type information to the TypeError, so the error message would read something like:
That's make debugging this and other similar problems easier.
Actually treating numpy integers (and other numpy scalar types) as integers would be a bonus.
Please note:
I wasn't the initial reporter of this bug/request. I am simple re-posting this (msgpack/msgpack#36 (comment)) into this repo.
The text was updated successfully, but these errors were encountered: