-
Notifications
You must be signed in to change notification settings - Fork 155
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 encoding numpy integer and floating point types #352
Conversation
It would be nice to handle numpy arrays as well. Something like: elif np_available and _isinstance_safe(o, np.ndarray):
result = o.tolist() |
Thanks, I have belatedly incorporated your suggestion, simplified the code and added a test for encoding to JSON, |
I wonder why not use encoder/decoder instead? I've seen people do this with fields being pandas Dataframes |
Thanks for your PR. Imo, I believe dataclasses-json should only support native types out of the box while 3rd-party types like numpy can be de/encoded with custom encoders. |
I'd say if the author added instead an example for docs with custom encoder/decoder for numpy, that would have helped many people. I'll wait a bit, if no reaction follows, I'll close this one and update docs with examples for both numpy and pandas. |
Closing this in favor of #470 |
Feel free to ignore if this is too much of an edge case for your module, but I found a need to serialise dataclasses to JSON that had NumPy types (int64 etc) in them. This PR adds support for encoding NumPy types, but only if the numpy module is available.