-
Notifications
You must be signed in to change notification settings - Fork 296
Fix NaN and Inf serialization #706
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ jupyter_core>=4.6.0 | |
nest-asyncio>=1.5 | ||
python-dateutil>=2.1 | ||
pyzmq>=13 | ||
simplejson | ||
tornado>=4.1 | ||
traitlets |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why the added dependency? I think we should be able to do this with stdlib json, since we always have before.
Uh oh!
There was an error while loading. Please reload this page.
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.
Before, we had
json_clean
in ipykernel that was going through all messages (making copies of lists and dicts) and replacingmath.inf
andmath.nan
manually.Unfortunately the standard json lib only allows two options:
allow_nan=True
: nan is serialized toNaN
, inf is serialized toInfinity
, which are both valid JS but not valid JSONallow_nan=False
: throw an exception for nan and inf without letting us a chance to serialize them tonull
(valid JSON) in thedefault
functionThere 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.
Arg, that's frustrating. And support for nan/inf is required somewhere? This is an artifact of earlier "never raise" goals, but I think maybe something that can't actually be serialized should raise. What breaks if these raise?
Uh oh!
There was an error while loading. Please reload this page.
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.
Both bqplot and pythreejs are failing now due to this. Arguably, those libraries should maybe provide valid JSON.
Edit:, for example, ipydatagrid has special serializers for those: https://github.com/bloomberg/ipydatagrid/blob/main/ipydatagrid/datagrid.py#L172-L178
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.
simplejson does the wrong thing for bytes:
we should have a test that verifies this, because the switch to simplejson should have caused tests to fail.
Can you add
to the list of pairs in
test_json_default
? And make sure the same json implementation is used?I think the bytes behavior is more important than the unsupported floats. matplotlib figures rely on it, for one.
What I think is the ideal behavior is to trigger a DeprecationWarning when these values are seen, but still coerce to null. I don't see a good way to do either with simplejson or stdlib json, though.
If supporting these values is deprecated, maybe the thing to do is to fallback on the old inefficient path:
What do you think?
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.
Yes, let's do that. Thanks!
Let's close this PR. I will add an extra test here like you suggested, and push a fix to ipykernel for the fallback to
json_clean
.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.
Actually, should we do this fallback to
json_clean
injupyter_client
? It'sjupyter_client
that does the dumpsThere 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.
Yeah, I think doing it here makes sense. I'm not sure ipykernel can add a catch in the right place.