Skip to content

Commit 8669568

Browse files
author
Jason Ng
committed
Remove unecessary type conversion
1 parent c3fb5e4 commit 8669568

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

pandas_gbq/gbq.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
771771
return final_df
772772

773773
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):
775775
r"""Load data from Google BigQuery using google-cloud-python
776776
777777
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,
810810
<https://cloud.google.com/bigquery/sql-reference/>`__
811811
configuration : dict (optional)
812812
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:
816816
-allow_large_results
817817
-create_disposition
818818
-default_dataset
@@ -861,38 +861,29 @@ def _wait_for_job(job):
861861
query_results = query_job.results()
862862

863863
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]
865865
data = rows
866866

867867
final_df = DataFrame(data=data,columns=columns)
868868

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-
879869
# Change the order of columns in the DataFrame based on provided list
880-
if col_order is not None:
870+
if col_order:
881871
if sorted(col_order) == sorted(final_df.columns):
882872
final_df = final_df[col_order]
883873
else:
884874
raise InvalidColumnOrder(
885875
'Column order does not match this DataFrame.'
886876
)
887877

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+
)
896887

897888
return final_df
898889

0 commit comments

Comments
 (0)