python-bigquery-pandas icon indicating copy to clipboard operation
python-bigquery-pandas copied to clipboard

Inserting boolean NULL values in BigQuery table — needs a test added

Open mdimrankhan112 opened this issue 7 years ago • 3 comments
trafficstars

For Boolean datatype, Big Query supports True,False and NULL values. However I am not able to insert NULL values using the dataFrame.to_gbq() method.

I tried with Boolean DataFrame column containing True, False, None values and with True, False, NaN values. Nothing seems to work.

Is there any method to do this or atleast a work around.

Thanks in advance!

mdimrankhan112 avatar Jan 05 '18 02:01 mdimrankhan112

Pandas doesn't support null values in bool columns.

There's an issue to be able to supply a schema; a schema of bool on an object column of True, False and NaN would work

As a hack, you could load a float column with 0, 1, and NaN, and run a query on BQ to cast as a bool

max-sixty avatar Jan 05 '18 16:01 max-sixty

Possibly fixed by https://github.com/googleapis/python-bigquery-pandas/pull/445 which adds support for the "new" boolean dtype, which does support NULL values.

tswast avatar Jan 19 '22 18:01 tswast

Re-opening, because we need a test case here: https://github.com/googleapis/python-bigquery-pandas/blob/main/tests/system/test_to_gbq.py

tswast avatar Jan 19 '22 18:01 tswast