-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Enable roundtrip pydantic->json->pydantic for float +- infinity and nan #7007
Comments
Yeah, it's an issue. 👍 cc @davidhewitt |
@samuelcolvin it looks like this will take some effort because |
Is there a workaround for this? The only thing I can think of is in my model changing this:
to
I'd prefer to have some way to read/write NaN values in the JSON... |
What is the plan though, just wait if/when serde includes such support? Looks like it's been four major releases of V2 already with this regression and it's significant. One example are non-nullable columns, it's much more efficient to keep NaN in arrow non-nullable |
Is there any possible workaround for this using custom serializers to serialize |
@davidhewitt I saw that you fixed Is this already useable from pydantic 2.5.0, or will we have to wait for an update to |
It should work in pydantic. |
@samuelcolvin, not via |
I can also confirm that |
Sorry yes this got closed before I managed to add the config setting to pydantic, will push a PR shortly... |
Initial Checks
Description
I've seen #1885 and other
np.inf, float(inf), float(nan)
related issues but it's not quite clear if the below is really an intended behavior.A pydantic model will by default allow
nan
andinf
for float values, thus I would like to be able to serialize these models to and then also from json. But that's currently not possible because those special float values are turned into'null'
in json and thus raise an error when trying to turn json back into a pydantic model.If this is indeed intended behavior, would an additional flag to
model_dump_json
be possible that would enable a similar behavior to python'sjson
module?Example Code
Python, Pydantic & OS Version
Selected Assignee: @Kludex
The text was updated successfully, but these errors were encountered: