GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cannot insert NaN and non-finite float values using Client.insert_rows() · Issue #696 · googleapis/python-bigquery

This repository was archived by the owner on Mar 6, 2026. It is now read-only.
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Cannot insert NaN and non-finite float values using Client.insert_rows() #696

Copy link
Copy link
Closed
#728
Closed
Cannot insert NaN and non-finite float values using Client.insert_rows()#696
#728
Copy link
Assignees
plamut
Labels
api: bigqueryIssues related to the googleapis/python-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@wmdrichards
wmdrichards
opened on Jun 11, 2021
Issue body actions

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

  1. 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

Activity

  1. product-auto-label
    added
    api: bigqueryIssues related to the googleapis/python-bigquery API.
    on Jun 11, 2021
  2. plamut
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Jun 11, 2021
  3. wmdrichards commented on Jun 11, 2021

    @wmdrichards
    wmdrichards
    on Jun 11, 2021
    Author
    More actions

    For anyone else running into this, using insert_rows_json is a valid workaround, as long as the row is already json-compatible

  4. plamut
    self-assigned this
    on Jun 17, 2021
  5. plamut
    changed the title [-]Cannot insert NaN values using Client.insert_rows[/-] [+]Cannot insert NaN and non-finite float values using Client.insert_rows()[/+] on Jun 29, 2021
  6. plamut commented on Jun 29, 2021

    @plamut
    plamut
    on Jun 29, 2021
    Contributor
    More actions

    Thanks for reporting and researching that. It turned out that non-finite floats were indeed problematic, too.

  7. plamut
    closed this as completedin #728on Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @plamut
    plamut

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.