-
Notifications
You must be signed in to change notification settings - Fork 223
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
orjson disregards numpy byte order #472
Comments
It should error rather than produce bad output. Is working with an array of big-endian values on a little-endian system a thing people do? |
This case came up for me when reading data in over a network, so it wasn't related to the endianness of the actual system I was working on, but rather the incoming data, which was then being re-serialized with orjson. As I understand it, some libraries/systems/protocols transport data over the network in a big-endian format. Mostly, I want to clarify the desired behavior -- in this case, a well-written error would indeed have been more clear than just outputting bytes that then caused more problems later on. I'm planning to do my own endianness check when reading data in, but it would certainly be helpful if orjson did a check as well (of course, serializing it properly is also an option). |
Ok, I've just had it raise an error in 3.10.1. Thanks for the report. |
When trying to serialize/deserialize numpy arrays, information about endianness is lost, causing data to fail to round-trip gracefully when a big-endian numpy array is passed in.
It would be helpful to check
test.dtype.byteorder == ">"
and byteswap big-endian numpy arrays so that serialization happens consistently. Or make it explicitly clear in the docs that orjson will not handle this.The text was updated successfully, but these errors were encountered: