-
Notifications
You must be signed in to change notification settings - Fork 0
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
Roundtrip JSON serialization/deserialization #17
Comments
Glad you are having fun :) Yes. I am surprised that the validation logic is different when parsing json and consider the fact that this doesn't work a bug. Finishing something up for the night and will return tomorrow. edit: it looks like there will have to be a change upstream in pydantic, will raise an issue with them tomorrow which will have more details in it |
Thanks for quick response. Looking forward to reading the issue on pydantic. Hopefully there are other workarounds or quick solution which can be merged in pydantic. |
An easy hack which works for me is add an
|
Ha, yes :) that should work, though we lose the ability to use the model with other array backends (shape and dtype validation should still work). The basic problem is that when parsing json, pydantic-core just uses the json schema and not the python validators. The json schema is correct for an n-dimensional array in json (a list of lists, parametrised according to the shape and dtype constraints), so it validates, but we need a way to hook on the coercion parts of the array interfaces at the end of the json parsing. Im going to look further if there's a way to chain a validator for just the json validation, and if not we might have to do some more monkeypatching |
Makes sense! I will be happy to test out your changes. Let me know if I can help in any way. |
Just letting you know i've figured this out and will issue a patch tonight or tomorrow <3. simpler than i thought, just need to change the way we're generating the json schema on the NDArray class (which we will soon rewrite anyway to make a proper generic, but that's another issue). edit: for more info - i had misunderstood how |
@sneakers-the-rat thanks for the explanation. After your explanation, I kinda understand |
No planned release cycle, I just fix bugs as they come up and make enhancements as requested at this point, but I am using semver and will do appropriate deprecation warnings in the case of breaking changes. Next major planned version 2.0.0 will be to replace the basic NDArray type with a proper Generic with TypeVarTuple while keeping current behavior, and moving away from nptyping with full removal in 3.0.0, so plenty of warning. Ill make this patch shortly Making a note with a checklist item to
|
for ur consideration: #20 |
Thanks for creating this essential missing piece from pydantic. I want to serialize a bunch of classes containing ndarray and deserialize them such they after initialization the class has elements with type ndarray. However, according to examples, that is not the supported behavior.
I am wondering if there is a way to get this behavior using numpydantic.
The text was updated successfully, but these errors were encountered: