Skip to content

Commit ce8ebe4

Browse files
committed
Merge branch 'bigquery-udf-resources'
2 parents 834a2ff + 028c8be commit ce8ebe4

File tree

4 files changed

+44
-34
lines changed

4 files changed

+44
-34
lines changed

doc/source/whatsnew/v0.19.0.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ Google BigQuery Enhancements
379379

380380
- The :func:`read_gbq` method has gained the ``dialect`` argument to allow users to specify whether to use BigQuery's legacy SQL or BigQuery's standard SQL. See the :ref:`docs <io.bigquery_reader>` for more details (:issue:`13615`).
381381
- The :func:`~DataFrame.to_gbq` method now allows the DataFrame column order to differ from the destination table schema (:issue:`11359`).
382-
- The :func:`read_gbq` method now allows query configuration preferences
383382

384383
.. _whatsnew_0190.errstate:
385384

doc/source/whatsnew/v0.20.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Other enhancements
3131
^^^^^^^^^^^^^^^^^^
3232

3333
- ``pd.read_excel`` now preserves sheet order when using ``sheetname=None`` (:issue:`9930`)
34+
- ``pd.io.gbq.read_gbq`` method now allows query configuration preferences
3435

3536

3637
.. _whatsnew_0200.api_breaking:

pandas/io/gbq.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,13 @@ def run_query(self, query, **kwargs):
395395
}
396396
}
397397
}
398-
query_config = kwargs.get('query_config')
399-
if query_config is not None:
400-
job_data['configuration']['query'].update(query_config)
398+
configuration = kwargs.get('configuration')
399+
if configuration is not None:
400+
if 'query' in configuration:
401+
job_data['configuration']['query']\
402+
.update(configuration['query'])
403+
else:
404+
job_data['configuration'] = configuration
401405

402406
self._start_timer()
403407
try:
@@ -687,11 +691,11 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
687691
.. versionadded:: 0.19.0
688692
689693
**kwargs: Arbitrary keyword arguments
690-
query_config (dict): query configuration parameters for job processing.
694+
configuration (dict): query config parameters for job processing.
691695
For more information see `BigQuery SQL Reference
692696
<https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.query>`
693697
694-
.. versionadded:: 0.19.0
698+
.. versionadded:: 0.20.0
695699
696700
Returns
697701
-------

pandas/io/tests/test_gbq.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -713,49 +713,55 @@ def test_invalid_option_for_sql_dialect(self):
713713

714714
def test_query_with_parameters(self):
715715
sql_statement = "SELECT @param1 + @param2 as VALID_RESULT"
716-
query_config = {
717-
"useLegacySql": False,
718-
"parameterMode": "named",
719-
"queryParameters": [
720-
{
721-
"name": "param1",
722-
"parameterType": {
723-
"type": "INTEGER"
716+
config = {
717+
'query': {
718+
"useLegacySql": False,
719+
"parameterMode": "named",
720+
"queryParameters": [
721+
{
722+
"name": "param1",
723+
"parameterType": {
724+
"type": "INTEGER"
725+
},
726+
"parameterValue": {
727+
"value": 1
728+
}
724729
},
725-
"parameterValue": {
726-
"value": 1
730+
{
731+
"name": "param2",
732+
"parameterType": {
733+
"type": "INTEGER"
734+
},
735+
"parameterValue": {
736+
"value": 2
737+
}
727738
}
728-
},
729-
{
730-
"name": "param2",
731-
"parameterType": {
732-
"type": "INTEGER"
733-
},
734-
"parameterValue": {
735-
"value": 2
736-
}
737-
}
738-
]
739+
]
740+
}
739741
}
740-
# Test that an invalid query without query_config
742+
# Test that an invalid query without query config
741743
with tm.assertRaises(ValueError):
742744
gbq.read_gbq(sql_statement, project_id=_get_project_id(),
743745
private_key=_get_private_key_path())
744746

745747
# Test that a correct query with query config
746748
df = gbq.read_gbq(sql_statement, project_id=_get_project_id(),
747749
private_key=_get_private_key_path(),
748-
query_config=query_config)
750+
configuration=config)
749751
tm.assert_frame_equal(df, DataFrame({'VALID_RESULT': [3]}))
750752

751-
def test_query_no_cache(self):
753+
def test_query_inside_configuration(self):
754+
query_no_use = 'SELECT "PI_WRONG" as VALID_STRING'
752755
query = 'SELECT "PI" as VALID_STRING'
753-
query_config = {
754-
"useQueryCache": False,
756+
config = {
757+
'query': {
758+
"query": query,
759+
"useQueryCache": False,
760+
}
755761
}
756-
df = gbq.read_gbq(query, project_id=_get_project_id(),
762+
df = gbq.read_gbq(query_no_use, project_id=_get_project_id(),
757763
private_key=_get_private_key_path(),
758-
query_config=query_config)
764+
configuration=config)
759765
tm.assert_frame_equal(df, DataFrame({'VALID_STRING': ['PI']}))
760766

761767

0 commit comments

Comments
 (0)