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
Add support for orjson, including direct numpy support #210
Conversation
32d4cf7
to
1e0cd28
Compare
Hi I think this can be superseded by #226 |
* `orjson` is supported as an additional submodule, as opposed to replacing the `json` submodule, as it's behavior and output types are slightly different than the `json` module.
Codecov Report
@@ Coverage Diff @@
## master #210 +/- ##
==========================================
- Coverage 90.57% 90.47% -0.10%
==========================================
Files 11 12 +1
Lines 1432 1470 +38
Branches 315 320 +5
==========================================
+ Hits 1297 1330 +33
- Misses 96 98 +2
- Partials 39 42 +3
Continue to review full report at Codecov.
|
Hi thanks! I didn't see your PR and actually updated this one today. I just pushed the changes. This takes a slightly different approach than yours. Rather than replacing the default
Either way, your changes are a bit simpler. @yukinarit should take a look at both PRs and decide which is the better direction, or maybe if some of the ideas from each should be combined. Cheers! |
Changing to $ python
Python 3.9.12 (main, Mar 26 2022, 15:51:15)
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import orjson
>>> import json
>>> json.dumps("😊")
'"\\ud83d\\ude0a"'
>>> json.dumps("😊").encode()
b'"\\ud83d\\ude0a"'
>>> orjson.dumps("😊")
b'"\xf0\x9f\x98\x8a"'
>>> json.dumps("😊").encode() == orjson.dumps("😊")
False
>>> orjson.loads(json.dumps("😊"))
'😊'
>>> json.loads(orjson.dumps("😊"))
'😊'
>>> Note that >>> json.dumps("😊", ensure_ascii=False)
'"😊"'
>>> json.dumps("😊", ensure_ascii=False).encode()
b'"\xf0\x9f\x98\x8a"' Additionally, mixing |
Sorry for the delay, I have been busy in the new environment. I finally got time to review The both of the PRs look great 👍 but kigawas's one is similar to what I was originally thinking, but I have the same concern as @kmsquire said. Changing return type from bytes to str is a big breaking change for the existing users. I guess most of the Pythonistas would prefer/expect JSON library to produce the output in str not bytes. The implicit conversion from bytes to str sounds unnecessary overhead, but pyserde's design principle is the best simplicity than the best performance as opposed to orison which aims to (de)serialize with the least overhead. Also, If you don't the That being said, @kigawas Is it ok to request to add |
Closing. Related functionality merged as part of #226. |
This pull request builds on #209, adding support for orjson and modifying numpy support to pass values through to orjson when that module is chosen as the (de)serializer and the appropriate flags are passed.
Still needs tests and probably discussion around how much of orjson to pull in.