-
-
Notifications
You must be signed in to change notification settings - Fork 704
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
Sanely handle Infinity/-Infinity values in JSON using ?_json_infinity=1 #332
Comments
https://docs.python.org/3/library/json.html#json.dump
|
I'm not sure what the correct thing to do here is. I don't want to throw a |
I think I'm going to return |
Here's how plotly handled this issue: plotly/plotly.py#203 - see also https://github.com/plotly/plotly.py/blob/213602df6c89b45ce2b811ed2591171c961408e7/plotly/utils.py#L137 |
And here's how django-rest-framework did it: https://github.com/encode/django-rest-framework/pull/4918/files |
Since my data is all flat lists of values I don't think I need to customize the JSON encoder itself (no need to deal with nested values). I'll fix the data on its way into the encoder instead. This will also help if I decide to move to uJSON for better performance #48 |
Maybe argument should be |
Actually SQLite doesn't handle NaN at all (it treats it as null) so I'm going to change this ticket to just deal with Infinity and -Infinity. |
I'm going with |
According to https://www.mail-archive.com/sqlite-users@mailinglists.sqlite.org/msg110573.html you can insert Infinity/-Infinity in raw SQL (as used by our fixtures) using 1e999 and -1e999. |
Demo:
|
It turns out if you load this CSV using
csvs-to-sqlite
you get an Infinity value in SQLite:csvs-to-sqlite infinity-bug.csv infinity-bug.db
I deployed this using:
Datasette outputs that as
Infinity
in the JSON format, which causes JavaScript errors.Demo
But... in Firefox that gets rendered like this:
And if you click the "Show charting options" button you get this error in the console:
The text was updated successfully, but these errors were encountered: