Skip to content

Commit 0ebe1e2

Browse files
committed
add table schema param to to_gbq fn
1 parent cec8c86 commit 0ebe1e2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pandas_gbq/gbq.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,8 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
768768

769769

770770
def to_gbq(dataframe, destination_table, project_id, chunksize=10000,
771-
verbose=True, reauth=False, if_exists='fail', private_key=None):
771+
verbose=True, reauth=False, if_exists='fail', private_key=None,
772+
table_schema=None):
772773
"""Write a DataFrame to a Google BigQuery table.
773774
774775
The main method a user calls to export pandas DataFrame contents to
@@ -831,7 +832,10 @@ def to_gbq(dataframe, destination_table, project_id, chunksize=10000,
831832
table = _Table(project_id, dataset_id, reauth=reauth,
832833
private_key=private_key)
833834

834-
table_schema = _generate_bq_schema(dataframe)
835+
if not table_schema:
836+
table_schema = _generate_bq_schema(dataframe)
837+
else:
838+
table_schema = dict(fields=table_schema)
835839

836840
# If table exists, check if_exists parameter
837841
if table.exists(table_id):

0 commit comments

Comments
 (0)