Skip to content

Empty strings inconsistently converted to NULL's when using df.to_gbq() #366

Closed
@jerome-asselin-ivadolabs

Description

Here is a reproducible example of inconsistent conversion of empty strings to NULL when exporting to Bigquery.

import pandas as pd
from google.cloud import bigquery

df1 = pd.DataFrame.from_dict([{'a': ""}])
df2 = pd.DataFrame.from_dict([{'a': "", 'b': ""}])

df1.to_gbq('aa_temp.df1') # Keeps empty string, as expected.
df2.to_gbq('aa_temp.df2') # Converts empty strings to null values.

client = bigquery.Client()
print(client.list_rows('aa_temp.df1').to_dataframe())
print(client.list_rows('aa_temp.df2').to_dataframe())

Actual Output:

  a
0  
      a     b
0  None  None

Expected Output:

  a
0  
      a     b
0    

Using python 3.7, pandas 1.2.4, pandas-gbq 0.15.0.

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: bigqueryIssues related to the googleapis/python-bigquery-pandas API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to 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