Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2984,7 +2984,7 @@ def load_table_from_dataframe(
and new_job_config.write_disposition != job.WriteDisposition.WRITE_TRUNCATE
):
try:
table = self.get_table(destination)
table = self.get_table(destination, timeout=timeout)
except core_exceptions.NotFound:
pass
else:
Expand Down Expand Up @@ -3172,7 +3172,7 @@ def load_table_from_json(
new_job_config.autodetect = True
else:
try:
self.get_table(destination)
self.get_table(destination, timeout=timeout)
except core_exceptions.NotFound:
new_job_config.autodetect = True
else:
Expand Down
38 changes: 38 additions & 0 deletions packages/google-cloud-bigquery/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9797,6 +9797,44 @@ def test_load_table_from_json_basic_use(self):
assert sent_config.schema is None
assert sent_config.autodetect

def test_load_table_from_dataframe_passes_timeout_to_table_lookup(self):
pandas = pytest.importorskip("pandas")
pytest.importorskip("pyarrow")

client = self._make_client()
dataframe = pandas.DataFrame({"id": [1]})

load_patch = mock.patch(
"google.cloud.bigquery.client.Client.load_table_from_file", autospec=True
)
get_table_patch = mock.patch(
"google.cloud.bigquery.client.Client.get_table",
autospec=True,
side_effect=google.api_core.exceptions.NotFound("Table not found"),
)

with load_patch, get_table_patch as get_table:
client.load_table_from_dataframe(dataframe, self.TABLE_REF, timeout=7.5)

get_table.assert_called_once_with(client, self.TABLE_REF, timeout=7.5)

def test_load_table_from_json_passes_timeout_to_table_lookup(self):
client = self._make_client()

load_patch = mock.patch(
"google.cloud.bigquery.client.Client.load_table_from_file", autospec=True
)
get_table_patch = mock.patch(
"google.cloud.bigquery.client.Client.get_table",
autospec=True,
side_effect=google.api_core.exceptions.NotFound("Table not found"),
)

with load_patch, get_table_patch as get_table:
client.load_table_from_json([{"id": 1}], self.TABLE_REF, timeout=7.5)

get_table.assert_called_once_with(client, self.TABLE_REF, timeout=7.5)

def test_load_table_from_json_non_default_args(self):
from google.cloud.bigquery import job
from google.cloud.bigquery.client import _DEFAULT_NUM_RETRIES
Expand Down
Loading