Skip to content

Commit 612f165

Browse files
authored
TST: use larger query for timeout test (#311)
* TST: use larger query for timeout test Also, allow jobTimeoutMs, as that is the name for the backend parameter. * blacken * FIX: No module named 'numpy.testing.decorators' * install pre-release pandas _after_ install dependencies
1 parent 2897b81 commit 612f165

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

ci/requirements-3.5.pip

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
numpy==1.13.3
12
pandas==0.19.0
23
google-auth==1.4.1
34
google-auth-oauthlib==0.0.1

ci/run_conda.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ conda update -q conda
1111
conda info -a
1212
conda create -q -n test-environment python=$PYTHON
1313
source activate test-environment
14+
REQ="ci/requirements-${PYTHON}-${PANDAS}"
15+
conda install -q --file "$REQ.conda";
16+
1417
if [[ "$PANDAS" == "NIGHTLY" ]]; then
1518
conda install -q numpy pytz python-dateutil;
1619
PRE_WHEELS="https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com";
@@ -19,8 +22,6 @@ else
1922
conda install -q pandas=$PANDAS;
2023
fi
2124

22-
REQ="ci/requirements-${PYTHON}-${PANDAS}"
23-
conda install -q --file "$REQ.conda";
2425
python setup.py develop --no-deps
2526

2627
# Run the tests

pandas_gbq/gbq.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,10 @@ def run_query(
480480
while query_reply.state != "DONE":
481481
self.log_elapsed_seconds(" Elapsed", "s. Waiting...")
482482

483-
timeout_ms = job_config["query"].get("timeoutMs")
483+
timeout_ms = job_config.get("jobTimeoutMs") or job_config[
484+
"query"
485+
].get("timeoutMs")
486+
timeout_ms = int(timeout_ms) if timeout_ms else None
484487
if timeout_ms and timeout_ms < self.get_elapsed_seconds() * 1000:
485488
raise QueryTimeout("Query timeout: {} ms".format(timeout_ms))
486489

tests/system/test_gbq.py

+31-12
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ def test_should_properly_handle_null_integers(self, project_id):
211211
credentials=self.credentials,
212212
dialect="legacy",
213213
)
214-
tm.assert_frame_equal(df, DataFrame({"null_integer": [None]}))
214+
tm.assert_frame_equal(
215+
df,
216+
DataFrame({"null_integer": pandas.Series([None], dtype="object")}),
217+
)
215218

216219
def test_should_properly_handle_valid_floats(self, project_id):
217220
from math import pi
@@ -772,17 +775,33 @@ def test_configuration_raises_value_error_with_multiple_config(
772775
)
773776

774777
def test_timeout_configuration(self, project_id):
775-
sql_statement = "SELECT 1"
776-
config = {"query": {"timeoutMs": 1}}
777-
# Test that QueryTimeout error raises
778-
with pytest.raises(gbq.QueryTimeout):
779-
gbq.read_gbq(
780-
sql_statement,
781-
project_id=project_id,
782-
credentials=self.credentials,
783-
configuration=config,
784-
dialect="legacy",
785-
)
778+
sql_statement = """
779+
SELECT
780+
SUM(bottles_sold) total_bottles,
781+
UPPER(category_name) category_name,
782+
magnitude,
783+
liquor.zip_code zip_code
784+
FROM `bigquery-public-data.iowa_liquor_sales.sales` liquor
785+
JOIN `bigquery-public-data.geo_us_boundaries.zip_codes` zip_codes
786+
ON liquor.zip_code = zip_codes.zip_code
787+
JOIN `bigquery-public-data.noaa_historic_severe_storms.tornado_paths` tornados
788+
ON liquor.date = tornados.storm_date
789+
WHERE ST_INTERSECTS(tornado_path_geom, zip_code_geom)
790+
GROUP BY category_name, magnitude, zip_code
791+
ORDER BY magnitude ASC, total_bottles DESC
792+
"""
793+
configs = [
794+
{"query": {"useQueryCache": False, "timeoutMs": 1}},
795+
{"query": {"useQueryCache": False}, "jobTimeoutMs": 1},
796+
]
797+
for config in configs:
798+
with pytest.raises(gbq.QueryTimeout):
799+
gbq.read_gbq(
800+
sql_statement,
801+
project_id=project_id,
802+
credentials=self.credentials,
803+
configuration=config,
804+
)
786805

787806
def test_query_response_bytes(self):
788807
assert self.gbq_connector.sizeof_fmt(999) == "999.0 B"

0 commit comments

Comments
 (0)