Skip to content

Commit 1542d29

Browse files
tswastjreback
authored andcommitted
[ENH] pull in warning for dialect change from pandas-gbq. (#22557)
1 parent 33f38b9 commit 1542d29

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

doc/source/whatsnew/v0.24.0.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ Other Enhancements
170170
- :meth:`Series.droplevel` and :meth:`DataFrame.droplevel` are now implemented (:issue:`20342`)
171171
- Added support for reading from Google Cloud Storage via the ``gcsfs`` library (:issue:`19454`)
172172
- :func:`to_gbq` and :func:`read_gbq` signature and documentation updated to
173-
reflect changes from the `Pandas-GBQ library version 0.5.0
174-
<https://pandas-gbq.readthedocs.io/en/latest/changelog.html#changelog-0-5-0>`__.
175-
(:issue:`21627`)
173+
reflect changes from the `Pandas-GBQ library version 0.6.0
174+
<https://pandas-gbq.readthedocs.io/en/latest/changelog.html#changelog-0-6-0>`__.
175+
(:issue:`21627`, :issue:`22557`)
176176
- New method :meth:`HDFStore.walk` will recursively walk the group hierarchy of an HDF5 file (:issue:`10932`)
177177
- :func:`read_html` copies cell data across ``colspan`` and ``rowspan``, and it treats all-``th`` table rows as headers if ``header`` kwarg is not given and there is no ``thead`` (:issue:`17054`)
178178
- :meth:`Series.nlargest`, :meth:`Series.nsmallest`, :meth:`DataFrame.nlargest`, and :meth:`DataFrame.nsmallest` now accept the value ``"all"`` for the ``keep`` argument. This keeps all ties for the nth largest/smallest value (:issue:`16818`)

pandas/io/gbq.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
""" Google BigQuery support """
22

3+
import warnings
4+
35

46
def _try_import():
57
# since pandas is a dependency of pandas-gbq
@@ -23,7 +25,7 @@ def _try_import():
2325

2426
def read_gbq(query, project_id=None, index_col=None, col_order=None,
2527
reauth=False, private_key=None, auth_local_webserver=False,
26-
dialect='legacy', location=None, configuration=None,
28+
dialect=None, location=None, configuration=None,
2729
verbose=None):
2830
"""
2931
Load data from Google BigQuery.
@@ -65,6 +67,8 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
6567
6668
*New in version 0.2.0 of pandas-gbq*.
6769
dialect : str, default 'legacy'
70+
Note: The default value is changing to 'standard' in a future verion.
71+
6872
SQL syntax dialect to use. Value can be one of:
6973
7074
``'legacy'``
@@ -76,6 +80,8 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
7680
compliant with the SQL 2011 standard. For more information
7781
see `BigQuery Standard SQL Reference
7882
<https://cloud.google.com/bigquery/docs/reference/standard-sql/>`__.
83+
84+
.. versionchanged:: 0.24.0
7985
location : str, optional
8086
Location where the query job should run. See the `BigQuery locations
8187
documentation
@@ -108,6 +114,17 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
108114
pandas.DataFrame.to_gbq : Write a DataFrame to Google BigQuery.
109115
"""
110116
pandas_gbq = _try_import()
117+
118+
if dialect is None:
119+
dialect = "legacy"
120+
warnings.warn(
121+
'The default value for dialect is changing to "standard" in a '
122+
'future version of pandas-gbq. Pass in dialect="legacy" to '
123+
"disable this warning.",
124+
FutureWarning,
125+
stacklevel=2,
126+
)
127+
111128
return pandas_gbq.read_gbq(
112129
query, project_id=project_id, index_col=index_col,
113130
col_order=col_order, reauth=reauth, verbose=verbose,

pandas/tests/io/test_gbq.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
import platform
55
import os
66

7+
try:
8+
from unittest import mock
9+
except ImportError:
10+
mock = pytest.importorskip("mock")
11+
712
import numpy as np
813
import pandas as pd
914
from pandas import compat, DataFrame
10-
1115
from pandas.compat import range
16+
import pandas.util.testing as tm
17+
1218

1319
pandas_gbq = pytest.importorskip('pandas_gbq')
1420

@@ -93,6 +99,16 @@ def make_mixed_dataframe_v2(test_size):
9399
index=range(test_size))
94100

95101

102+
def test_read_gbq_without_dialect_warns_future_change(monkeypatch):
103+
# Default dialect is changing to standard SQL. See:
104+
# https://github.com/pydata/pandas-gbq/issues/195
105+
mock_read_gbq = mock.Mock()
106+
mock_read_gbq.return_value = DataFrame([[1.0]])
107+
monkeypatch.setattr(pandas_gbq, 'read_gbq', mock_read_gbq)
108+
with tm.assert_produces_warning(FutureWarning):
109+
pd.read_gbq("SELECT 1")
110+
111+
96112
@pytest.mark.single
97113
class TestToGBQIntegrationWithServiceAccountKeyPath(object):
98114

0 commit comments

Comments
 (0)