Trying to insert a NaN using Client.insert_rows fails. I tracked it down to
def _float_to_json(value):
"""Coerce 'value' to an JSON-compatible representation."""
return value if value is None else float(value)
which should return "NaN" to be compatible with the REST API. Currently it returns an actual nan float value. Probably similar issues occur with other non-finite floats.
Environment details
- OS type and version:
- Python version:
Python 3.6.8
- pip version:
pip 21.1
google-cloud-bigquery version: 2.20.0
Steps to reproduce
- Try to insert a NaN value into existing table
Code example
from google.cloud.bigquery import Client
client = Client(project='bar')
client.insert_rows(table=client.get_table('foo'), rows=[{'bar': float('NaN')}])
Stack trace
google.api_core.exceptions.BadRequest: 400 POST (REDACTED): Invalid JSON payload received. Unexpected token.
json": {"bar": NaN}, "insertId": "1
Trying to insert a NaN using
Client.insert_rowsfails. I tracked it down towhich should return "NaN" to be compatible with the REST API. Currently it returns an actual nan float value. Probably similar issues occur with other non-finite floats.
Environment details
Python 3.6.8pip 21.1google-cloud-bigqueryversion:2.20.0Steps to reproduce
Code example
Stack trace