@@ -771,7 +771,7 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
771
771
return final_df
772
772
773
773
def from_gbq (query , project_id = None , index_col = None , col_order = None ,
774
- private_key = None , dialect = 'legacy' , configuration = None , ** kwargs ):
774
+ private_key = None , dialect = 'legacy' , configuration = None , ** kwargs ):
775
775
r"""Load data from Google BigQuery using google-cloud-python
776
776
777
777
The main method a user calls to execute a Query in Google BigQuery
@@ -810,21 +810,14 @@ def from_gbq(query, project_id=None, index_col=None, col_order=None,
810
810
<https://cloud.google.com/bigquery/sql-reference/>`__
811
811
configuration : dict (optional)
812
812
Because of current limitations (https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2765)
813
- only a certain number of configuration settings are currently implemented. You can set them with
814
- like: `from_gbq(q,configuration={'allow_large_results':True,'use_legacy_sql':False})`
815
- Allowable settings:
816
- -allow_large_results
817
- -create_disposition
818
- -default_dataset
819
- -destination
820
- -flatten_results
821
- -priority
822
- -use_query_cache
823
- -use_legacy_sql
824
- -dry_run
825
- -write_disposition
826
- -maximum_billing_tier
827
- -maximum_bytes_billed
813
+ only some configuration settings are currently implemented. You can pass them
814
+ along like in the following:
815
+ `from_gbq(q,configuration={'allow_large_results':True,'maximum_billing_tier':2})`
816
+
817
+ Example allowable settings:
818
+ allow_large_results, create_disposition, default_dataset, destination
819
+ flatten_results, priority, use_query_cache, use_legacy_sql, dry_run,
820
+ write_disposition, udf_resources, maximum_billing_tier, maximum_bytes_billed
828
821
829
822
Returns
830
823
-------
@@ -861,38 +854,29 @@ def _wait_for_job(job):
861
854
query_results = query_job .results ()
862
855
863
856
rows , total_rows , page_token = query_results .fetch_data ()
864
- columns = [field .name for field in query_results .schema ]
857
+ columns = [field .name for field in query_results .schema ]
865
858
data = rows
866
859
867
860
final_df = DataFrame (data = data ,columns = columns )
868
861
869
- # Reindex the DataFrame on the provided column
870
- if index_col is not None :
871
- if index_col in final_df .columns :
872
- final_df .set_index (index_col , inplace = True )
873
- else :
874
- raise InvalidIndexColumn (
875
- 'Index column "{0}" does not exist in DataFrame.'
876
- .format (index_col )
877
- )
878
-
879
862
# Change the order of columns in the DataFrame based on provided list
880
- if col_order is not None :
863
+ if col_order :
881
864
if sorted (col_order ) == sorted (final_df .columns ):
882
865
final_df = final_df [col_order ]
883
866
else :
884
867
raise InvalidColumnOrder (
885
868
'Column order does not match this DataFrame.'
886
869
)
887
870
888
- # cast BOOLEAN and INTEGER columns from object to bool/int
889
- # if they dont have any nulls
890
- type_map = {'BOOLEAN' : bool , 'INTEGER' : int }
891
- for field in query_results .schema :
892
- if field .field_type in type_map and \
893
- final_df [field .name ].notnull ().all ():
894
- final_df [field .name ] = \
895
- final_df [field .name ].astype (type_map [field .field_type ])
871
+ # Reindex the DataFrame on the provided column
872
+ if index_col :
873
+ if index_col in final_df .columns :
874
+ final_df .set_index (index_col , inplace = True )
875
+ else :
876
+ raise InvalidIndexColumn (
877
+ 'Index column "{0}" does not exist in DataFrame.'
878
+ .format (index_col )
879
+ )
896
880
897
881
return final_df
898
882
0 commit comments