-
Notifications
You must be signed in to change notification settings - Fork 235
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 a custom Serializer/Deserializer to fix Nan and Infinity float #888
Conversation
e306f56
to
47e9a61
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #888 +/- ##
==========================================
- Coverage 93.79% 84.06% -9.73%
==========================================
Files 105 110 +5
Lines 15252 18052 +2800
Branches 25 25
==========================================
+ Hits 14305 15176 +871
- Misses 941 2870 +1929
Partials 6 6
... and 7 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
CodSpeed Performance ReportMerging #888 will degrade performances by 13.48%Comparing Summary
Benchmarks breakdown
|
47e9a61
to
671c44d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This is looking pretty good to me, just a thought on high-level design at this point.
Also, I wonder whether we want to merge this before we can support deserializing Infinity
and NaN
? It would break round-trips.
if (v.is_nan() || v.is_infinite()) && !self.allow_inf_nan { | ||
return serializer.serialize_none(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going back and forth whether allow_inf_nan
is the right config option here. I wonder if allow_inf_nan == false
should actually lead to an error when serializing, like Python's json.dump
will error with allow_nan=False
.
Maybe instead we need float_inf_nan_mode
similar to timedelta_mode
and bytes_mode
, with two string options? ("constants"
or "null"
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the difference? "constants" triggers an error?
Maybe I can create a new folder in the |
Can you give me a sense of which code you're wanting to move in there? |
I was thinking of creating a module in src called serde to group together the PythonSerializer and PythonDeserializer:
Adapted from the ser.rs, de.rs and read.rs of https://github.com/serde-rs/json/tree/master/src WDYT? @davidhewitt |
Seems reasonable to me, want to go ahead and add that as a commit on top so that we can always back out if it doesn't sit well? |
Done in this commit 6b0063c, that's a lot of code... |
fa329a1
to
6b0063c
Compare
Crikey, that's a lot of code. If I understand correctly, it's a copy-paste from I think probably this is necessary, though I wonder if we can simplify it at all. I'll try and read through it 🤔 |
I looked at this repository(https://github.com/getsentry/rust-json-forensics/) that adds a transformation to serde_json, which could be an interesting approach. WDYT @davidhewitt ? |
@davidhewitt Sorry to ping you, but what should I do about this MR? |
Yes sorry for the long time of inactivity here from me. A first implementation of
I think we want the following options:
I suppose the default of |
Change Summary
Add a custom Serializer to fix Nan and Infinity float
Related issue number
closes #872
Checklist
pydantic-core
(except for expected changes)