1
1
""" Google BigQuery support """
2
2
3
- from pandas .util .decorators import docstring_wrapper
4
-
5
3
6
4
def _try_import ():
7
5
# since pandas is a dependency of pandas-gbq
@@ -25,6 +23,72 @@ def _try_import():
25
23
def read_gbq (query , project_id = None , index_col = None , col_order = None ,
26
24
reauth = False , verbose = True , private_key = None , dialect = 'legacy' ,
27
25
** kwargs ):
26
+ r"""Load data from Google BigQuery.
27
+
28
+ The main method a user calls to execute a Query in Google BigQuery
29
+ and read results into a pandas DataFrame.
30
+
31
+ Google BigQuery API Client Library v2 for Python is used.
32
+ Documentation is available `here
33
+ <https://developers.google.com/api-client-library/python/apis/bigquery/v2>`__
34
+
35
+ Authentication to the Google BigQuery service is via OAuth 2.0.
36
+
37
+ - If "private_key" is not provided:
38
+
39
+ By default "application default credentials" are used.
40
+
41
+ If default application credentials are not found or are restrictive,
42
+ user account credentials are used. In this case, you will be asked to
43
+ grant permissions for product name 'pandas GBQ'.
44
+
45
+ - If "private_key" is provided:
46
+
47
+ Service account credentials will be used to authenticate.
48
+
49
+ Parameters
50
+ ----------
51
+ query : str
52
+ SQL-Like Query to return data values
53
+ project_id : str
54
+ Google BigQuery Account project ID.
55
+ index_col : str (optional)
56
+ Name of result column to use for index in results DataFrame
57
+ col_order : list(str) (optional)
58
+ List of BigQuery column names in the desired order for results
59
+ DataFrame
60
+ reauth : boolean (default False)
61
+ Force Google BigQuery to reauthenticate the user. This is useful
62
+ if multiple accounts are used.
63
+ verbose : boolean (default True)
64
+ Verbose output
65
+ private_key : str (optional)
66
+ Service account private key in JSON format. Can be file path
67
+ or string contents. This is useful for remote server
68
+ authentication (eg. jupyter iPython notebook on remote host)
69
+
70
+ dialect : {'legacy', 'standard'}, default 'legacy'
71
+ 'legacy' : Use BigQuery's legacy SQL dialect.
72
+ 'standard' : Use BigQuery's standard SQL (beta), which is
73
+ compliant with the SQL 2011 standard. For more information
74
+ see `BigQuery SQL Reference
75
+ <https://cloud.google.com/bigquery/sql-reference/>`__
76
+
77
+ **kwargs : Arbitrary keyword arguments
78
+ configuration (dict): query config parameters for job processing.
79
+ For example:
80
+
81
+ configuration = {'query': {'useQueryCache': False}}
82
+
83
+ For more information see `BigQuery SQL Reference
84
+ <https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.query>`__
85
+
86
+ Returns
87
+ -------
88
+ df: DataFrame
89
+ DataFrame representing results of query
90
+
91
+ """
28
92
pandas_gbq = _try_import ()
29
93
return pandas_gbq .read_gbq (
30
94
query , project_id = project_id ,
@@ -35,18 +99,10 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
35
99
** kwargs )
36
100
37
101
38
- read_gbq = docstring_wrapper (read_gbq ,
39
- lambda : _try_import ().read_gbq .__doc__ )
40
-
41
-
42
102
def to_gbq (dataframe , destination_table , project_id , chunksize = 10000 ,
43
103
verbose = True , reauth = False , if_exists = 'fail' , private_key = None ):
44
104
pandas_gbq = _try_import ()
45
105
pandas_gbq .to_gbq (dataframe , destination_table , project_id ,
46
106
chunksize = chunksize ,
47
107
verbose = verbose , reauth = reauth ,
48
108
if_exists = if_exists , private_key = private_key )
49
-
50
-
51
- to_gbq = docstring_wrapper (to_gbq ,
52
- lambda : _try_import ().to_gbq .__doc__ )
0 commit comments