@@ -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,9 +810,9 @@ 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:
813
+ only a certain number of configuration settings are currently implemented. You can set them
814
+ like in the following : `from_gbq(q,configuration={'allow_large_results':True,'use_legacy_sql':False})`
815
+ Current allowable settings:
816
816
-allow_large_results
817
817
-create_disposition
818
818
-default_dataset
@@ -861,38 +861,29 @@ def _wait_for_job(job):
861
861
query_results = query_job .results ()
862
862
863
863
rows , total_rows , page_token = query_results .fetch_data ()
864
- columns = [field .name for field in query_results .schema ]
864
+ columns = [field .name for field in query_results .schema ]
865
865
data = rows
866
866
867
867
final_df = DataFrame (data = data ,columns = columns )
868
868
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
869
# Change the order of columns in the DataFrame based on provided list
880
- if col_order is not None :
870
+ if col_order :
881
871
if sorted (col_order ) == sorted (final_df .columns ):
882
872
final_df = final_df [col_order ]
883
873
else :
884
874
raise InvalidColumnOrder (
885
875
'Column order does not match this DataFrame.'
886
876
)
887
877
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 ])
878
+ # Reindex the DataFrame on the provided column
879
+ if index_col :
880
+ if index_col in final_df .columns :
881
+ final_df .set_index (index_col , inplace = True )
882
+ else :
883
+ raise InvalidIndexColumn (
884
+ 'Index column "{0}" does not exist in DataFrame.'
885
+ .format (index_col )
886
+ )
896
887
897
888
return final_df
898
889
0 commit comments