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 — Bug: `dataframe_to_json_generator` doesn't support `pandas.NA` type · Issue #729 · 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.

Bug: dataframe_to_json_generator doesn't support pandas.NA type #729

Copy link
Copy link
Closed
#750
Closed
Bug: dataframe_to_json_generator doesn't support pandas.NA type#729
#750
Copy link
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

@LinuxChristian
LinuxChristian
opened on Jun 29, 2021
Issue body actions

Environment details

  • OS type and version: Ubuntu 20.04.2
  • Python version: 3.9.4
  • pip version: 21.1.2
  • google-cloud-bigquery version: 2.20.0

Steps to reproduce

  1. Run the code example below

Code example

import pandas
from google.cloud import bigquery

df = pandas.DataFrame({
    "series_a": [1, 2, pandas.NA]
})

json_iter = bigquery._pandas_helpers.dataframe_to_json_generator(df)
for row in json_iter:
    print(row)

Stack trace

{'series_a': 1}
{'series_a': 2}
Traceback (most recent call last):
  File "/home/christian/code/bug_example.py", line 11, in <module>
    for row in json_iter:
  File "/home/christian/miniconda3/envs/data-services-prod/lib/python3.9/site-packages/google/cloud/bigquery/_pandas_helpers.py", line 783, in dataframe_to_json_generator
    if value != value:
  File "pandas/_libs/missing.pyx", line 360, in pandas._libs.missing.NAType.__bool__
TypeError: boolean value of NA is ambiguous

Suggested fix

Starting with pandas 1.0, an experimental pandas.NA value (singleton) is available to represent scalar missing values as
opposed to numpy.nan. Comparing the variable with itself (value != value) results in a TypeError as the pandas.NA value doesn't support type-casting to boolean.

I am planning to make a PR that switches the syntax value != value on _pandas_helpers.py#L783 to use the pandas.isna function but wanted to check if there is a better solution before I submit a patch?

Activity

  1. product-auto-label
    added
    api: bigqueryIssues related to the googleapis/python-bigquery API.
    on Jun 29, 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 30, 2021
  3. tswast commented on Jul 8, 2021

    @tswast
    tswast
    on Jul 8, 2021
    Contributor
    More actions

    Yes, I agree that's the problematic line. I'd like NaN to continue to serve the same purpose, but happy to also support NA.

  4. plamut commented on Jul 10, 2021

    @plamut
    plamut
    on Jul 10, 2021
    Contributor
    More actions

    I can probably have a closer look at this some time next week.

  5. LinuxChristian commented on Jul 11, 2021

    @LinuxChristian
    LinuxChristian
    on Jul 11, 2021
    ContributorAuthor
    More actions

    I completely forgot to submit my PR after opening this issue, sorry about that. I looked through the code and switching to pandas.isna seemed like the obvious solution since the function only works for pandas.DataFrame objects.

    Reacted by Peter Lamut
  6. plamut
    closed this as completedin #750on Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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.