Skip to content

Commit a763cf0

Browse files
author
Jason Ng
committed
Remove unecessary type conversion
Tweaking docstring
1 parent c3fb5e4 commit a763cf0

File tree

1 file changed

+20
-36
lines changed

1 file changed

+20
-36
lines changed

pandas_gbq/gbq.py

Lines changed: 20 additions & 36 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,21 +810,14 @@ 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:
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
828821
829822
Returns
830823
-------
@@ -861,38 +854,29 @@ def _wait_for_job(job):
861854
query_results = query_job.results()
862855

863856
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]
865858
data = rows
866859

867860
final_df = DataFrame(data=data,columns=columns)
868861

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-
879862
# Change the order of columns in the DataFrame based on provided list
880-
if col_order is not None:
863+
if col_order:
881864
if sorted(col_order) == sorted(final_df.columns):
882865
final_df = final_df[col_order]
883866
else:
884867
raise InvalidColumnOrder(
885868
'Column order does not match this DataFrame.'
886869
)
887870

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

897881
return final_df
898882

0 commit comments

Comments
 (0)