@@ -232,20 +232,28 @@ def read_gbq(
232
232
query_or_table : str ,
233
233
* ,
234
234
index_col : Iterable [str ] | str = (),
235
- col_order : Iterable [str ] = (),
235
+ columns : Iterable [str ] = (),
236
236
max_results : Optional [int ] = None ,
237
237
filters : third_party_pandas_gbq .FiltersType = (),
238
238
use_cache : bool = True ,
239
+ col_order : Iterable [str ] = (),
239
240
# Add a verify index argument that fails if the index is not unique.
240
241
) -> dataframe .DataFrame :
241
242
# TODO(b/281571214): Generate prompt to show the progress of read_gbq.
242
- query_or_table = self ._filters_to_query (query_or_table , col_order , filters )
243
+ if columns and col_order :
244
+ raise ValueError (
245
+ "Must specify either columns (preferred) or col_order, not both"
246
+ )
247
+ elif col_order :
248
+ columns = col_order
249
+
250
+ query_or_table = self ._filters_to_query (query_or_table , columns , filters )
243
251
244
252
if _is_query (query_or_table ):
245
253
return self ._read_gbq_query (
246
254
query_or_table ,
247
255
index_col = index_col ,
248
- col_order = col_order ,
256
+ columns = columns ,
249
257
max_results = max_results ,
250
258
api_name = "read_gbq" ,
251
259
use_cache = use_cache ,
@@ -257,7 +265,7 @@ def read_gbq(
257
265
return self ._read_gbq_table (
258
266
query_or_table ,
259
267
index_col = index_col ,
260
- col_order = col_order ,
268
+ columns = columns ,
261
269
max_results = max_results ,
262
270
api_name = "read_gbq" ,
263
271
use_cache = use_cache ,
@@ -388,9 +396,10 @@ def read_gbq_query(
388
396
query : str ,
389
397
* ,
390
398
index_col : Iterable [str ] | str = (),
391
- col_order : Iterable [str ] = (),
399
+ columns : Iterable [str ] = (),
392
400
max_results : Optional [int ] = None ,
393
401
use_cache : bool = True ,
402
+ col_order : Iterable [str ] = (),
394
403
) -> dataframe .DataFrame :
395
404
"""Turn a SQL query into a DataFrame.
396
405
@@ -442,10 +451,17 @@ def read_gbq_query(
442
451
"""
443
452
# NOTE: This method doesn't (yet) exist in pandas or pandas-gbq, so
444
453
# these docstrings are inline.
454
+ if columns and col_order :
455
+ raise ValueError (
456
+ "Must specify either columns (preferred) or col_order, not both"
457
+ )
458
+ elif col_order :
459
+ columns = col_order
460
+
445
461
return self ._read_gbq_query (
446
462
query = query ,
447
463
index_col = index_col ,
448
- col_order = col_order ,
464
+ columns = columns ,
449
465
max_results = max_results ,
450
466
api_name = "read_gbq_query" ,
451
467
use_cache = use_cache ,
@@ -456,7 +472,7 @@ def _read_gbq_query(
456
472
query : str ,
457
473
* ,
458
474
index_col : Iterable [str ] | str = (),
459
- col_order : Iterable [str ] = (),
475
+ columns : Iterable [str ] = (),
460
476
max_results : Optional [int ] = None ,
461
477
api_name : str = "read_gbq_query" ,
462
478
use_cache : bool = True ,
@@ -492,7 +508,7 @@ def _read_gbq_query(
492
508
return self .read_gbq_table (
493
509
f"{ destination .project } .{ destination .dataset_id } .{ destination .table_id } " ,
494
510
index_col = index_cols ,
495
- col_order = col_order ,
511
+ columns = columns ,
496
512
max_results = max_results ,
497
513
use_cache = use_cache ,
498
514
)
@@ -502,9 +518,10 @@ def read_gbq_table(
502
518
query : str ,
503
519
* ,
504
520
index_col : Iterable [str ] | str = (),
505
- col_order : Iterable [str ] = (),
521
+ columns : Iterable [str ] = (),
506
522
max_results : Optional [int ] = None ,
507
523
use_cache : bool = True ,
524
+ col_order : Iterable [str ] = (),
508
525
) -> dataframe .DataFrame :
509
526
"""Turn a BigQuery table into a DataFrame.
510
527
@@ -521,10 +538,17 @@ def read_gbq_table(
521
538
"""
522
539
# NOTE: This method doesn't (yet) exist in pandas or pandas-gbq, so
523
540
# these docstrings are inline.
541
+ if columns and col_order :
542
+ raise ValueError (
543
+ "Must specify either columns (preferred) or col_order, not both"
544
+ )
545
+ elif col_order :
546
+ columns = col_order
547
+
524
548
return self ._read_gbq_table (
525
549
query = query ,
526
550
index_col = index_col ,
527
- col_order = col_order ,
551
+ columns = columns ,
528
552
max_results = max_results ,
529
553
api_name = "read_gbq_table" ,
530
554
use_cache = use_cache ,
@@ -583,7 +607,7 @@ def _read_gbq_table(
583
607
query : str ,
584
608
* ,
585
609
index_col : Iterable [str ] | str = (),
586
- col_order : Iterable [str ] = (),
610
+ columns : Iterable [str ] = (),
587
611
max_results : Optional [int ] = None ,
588
612
api_name : str ,
589
613
use_cache : bool = True ,
@@ -602,10 +626,10 @@ def _read_gbq_table(
602
626
table_ref , api_name = api_name , use_cache = use_cache
603
627
)
604
628
605
- for key in col_order :
629
+ for key in columns :
606
630
if key not in table_expression .columns :
607
631
raise ValueError (
608
- f"Column '{ key } ' of `col_order ` not found in this table."
632
+ f"Column '{ key } ' of `columns ` not found in this table."
609
633
)
610
634
611
635
if isinstance (index_col , str ):
@@ -619,8 +643,8 @@ def _read_gbq_table(
619
643
f"Column `{ key } ` of `index_col` not found in this table."
620
644
)
621
645
622
- if col_order :
623
- table_expression = table_expression .select ([* index_cols , * col_order ])
646
+ if columns :
647
+ table_expression = table_expression .select ([* index_cols , * columns ])
624
648
625
649
# If the index is unique and sortable, then we don't need to generate
626
650
# an ordering column.
@@ -719,7 +743,7 @@ def _read_bigquery_load_job(
719
743
* ,
720
744
job_config : bigquery .LoadJobConfig ,
721
745
index_col : Iterable [str ] | str = (),
722
- col_order : Iterable [str ] = (),
746
+ columns : Iterable [str ] = (),
723
747
) -> dataframe .DataFrame :
724
748
if isinstance (index_col , str ):
725
749
index_cols = [index_col ]
@@ -760,7 +784,7 @@ def _read_bigquery_load_job(
760
784
return self .read_gbq_table (
761
785
table_id ,
762
786
index_col = index_col ,
763
- col_order = col_order ,
787
+ columns = columns ,
764
788
)
765
789
766
790
def read_gbq_model (self , model_name : str ):
@@ -959,13 +983,13 @@ def read_csv(
959
983
if index_col is None :
960
984
index_col = ()
961
985
962
- # usecols should only be an iterable of strings (column names) for use as col_order in read_gbq.
963
- col_order : Tuple [Any , ...] = tuple ()
986
+ # usecols should only be an iterable of strings (column names) for use as columns in read_gbq.
987
+ columns : Tuple [Any , ...] = tuple ()
964
988
if usecols is not None :
965
989
if isinstance (usecols , Iterable ) and all (
966
990
isinstance (col , str ) for col in usecols
967
991
):
968
- col_order = tuple (col for col in usecols )
992
+ columns = tuple (col for col in usecols )
969
993
else :
970
994
raise NotImplementedError (
971
995
"BigQuery engine only supports an iterable of strings for `usecols`. "
@@ -1000,7 +1024,7 @@ def read_csv(
1000
1024
table ,
1001
1025
job_config = job_config ,
1002
1026
index_col = index_col ,
1003
- col_order = col_order ,
1027
+ columns = columns ,
1004
1028
)
1005
1029
else :
1006
1030
if any (arg in kwargs for arg in ("chunksize" , "iterator" )):
0 commit comments