?_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

@ -864,3 +864,15 @@ class LimitedWriter:
self.limit_bytes
))
self.writer.write(bytes)
_infinities = {float("inf"), float("-inf")}
def remove_infinites(row):
if any((c in _infinities) if isinstance(c, float) else 0 for c in row):
return [
None if (isinstance(c, float) and c in _infinities) else c
for c in row
]
return row