?_json_infinity=1 for handling Infinity/-Infinity - fixes #332

This commit is contained in:
Simon Willison 2018-07-23 20:07:57 -07:00
commit 700d83d8ad
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
5 changed files with 64 additions and 2 deletions

View file

@ -20,8 +20,10 @@ from datasette.utils import (
path_from_row_pks,
path_with_added_args,
path_with_format,
remove_infinites,
resolve_table_and_format,
to_css_class
to_css_class,
value_as_boolean,
)
ureg = pint.UnitRegistry()
@ -334,6 +336,12 @@ class BaseView(RenderMixin):
data["rows"], data["columns"], json_cols,
)
# unless _json_infinity=1 requested, replace infinity with None
if "rows" in data and not value_as_boolean(
request.args.get("_json_infinity", "0")
):
data["rows"] = [remove_infinites(row) for row in data["rows"]]
# Deal with the _shape option
shape = request.args.get("_shape", "arrays")
if shape == "arrayfirst":