Uploads a Pandas entity dataframe into a BigQuery table and returns the resulting table
(
client: Client,
table_name: str,
entity_df: Union[pd.DataFrame, str],
)
| 1398 | |
| 1399 | |
| 1400 | def _upload_entity_df( |
| 1401 | client: Client, |
| 1402 | table_name: str, |
| 1403 | entity_df: Union[pd.DataFrame, str], |
| 1404 | ) -> Table: |
| 1405 | """Uploads a Pandas entity dataframe into a BigQuery table and returns the resulting table""" |
| 1406 | job: Union[bigquery.job.query.QueryJob, bigquery.job.load.LoadJob] |
| 1407 | |
| 1408 | if isinstance(entity_df, str): |
| 1409 | job = client.query(f"CREATE TABLE `{table_name}` AS ({entity_df})") |
| 1410 | |
| 1411 | elif isinstance(entity_df, pd.DataFrame): |
| 1412 | # Drop the index so that we don't have unnecessary columns |
| 1413 | entity_df.reset_index(drop=True, inplace=True) |
| 1414 | job = client.load_table_from_dataframe(entity_df, table_name) |
| 1415 | else: |
| 1416 | raise InvalidEntityType(type(entity_df)) |
| 1417 | |
| 1418 | block_until_done(client, job) |
| 1419 | |
| 1420 | # Ensure that the table expires after some time |
| 1421 | table = client.get_table(table=table_name) |
| 1422 | table.expires = _utc_now() + timedelta(minutes=30) |
| 1423 | client.update_table(table, ["expires"]) |
| 1424 | |
| 1425 | return table |
| 1426 | |
| 1427 | |
| 1428 | def _get_entity_schema( |
no test coverage detected