Skip to content

Commit 9a9a48e

Browse files
aktechmax-sixty
authored andcommitted
Load data with user defined schema (#150)
* Load data with the supplied schema * Test for upload data with different df and user schema
1 parent ed17886 commit 9a9a48e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pandas_gbq/gbq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def load_data(
562562
try:
563563
for remaining_rows in _load.load_chunks(
564564
self.client, dataframe, dataset_id, table_id,
565-
chunksize=chunksize):
565+
chunksize=chunksize, schema=schema):
566566
self._print("\rLoad is {0}% Complete".format(
567567
((total_rows - remaining_rows) * 100) / total_rows))
568568
except self.http_error as ex:

pandas_gbq/tests/test_gbq.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,23 @@ def test_upload_data_with_timestamp(self):
14121412
result = result_df['times'].sort_values()
14131413
tm.assert_numpy_array_equal(expected.values, result.values)
14141414

1415+
def test_upload_data_with_different_df_and_user_schema(self):
1416+
df = tm.makeMixedDataFrame()
1417+
df['A'] = df['A'].astype(str)
1418+
df['B'] = df['B'].astype(str)
1419+
test_id = "22"
1420+
test_schema = [{'name': 'A', 'type': 'FLOAT'},
1421+
{'name': 'B', 'type': 'FLOAT'},
1422+
{'name': 'C', 'type': 'STRING'},
1423+
{'name': 'D', 'type': 'TIMESTAMP'}]
1424+
destination_table = self.destination_table + test_id
1425+
gbq.to_gbq(df, destination_table, _get_project_id(),
1426+
private_key=self.credentials,
1427+
table_schema=test_schema)
1428+
dataset, table = destination_table.split('.')
1429+
assert self.table.verify_schema(dataset, table,
1430+
dict(fields=test_schema))
1431+
14151432
def test_list_dataset(self):
14161433
dataset_id = self.dataset_prefix + "1"
14171434
assert dataset_id in self.dataset.datasets()

0 commit comments

Comments
 (0)