@@ -2724,6 +2724,41 @@ def test_reload_w_alternate_client(self):
2724
2724
self .assertEqual (req ['path' ], PATH )
2725
2725
self ._verifyResourceProperties (job , RESOURCE )
2726
2726
2727
+ @unittest .skipIf (pandas is None , 'Requires `pandas`' )
2728
+ def test_to_dataframe (self ):
2729
+ begun_resource = self ._make_resource ()
2730
+ query_resource = {
2731
+ 'jobComplete' : True ,
2732
+ 'jobReference' : {
2733
+ 'projectId' : self .PROJECT ,
2734
+ 'jobId' : self .JOB_ID ,
2735
+ },
2736
+ 'schema' : {
2737
+ 'fields' : [
2738
+ {'name' : 'name' , 'type' : 'STRING' , 'mode' : 'NULLABLE' },
2739
+ {'name' : 'age' , 'type' : 'INTEGER' , 'mode' : 'NULLABLE' },
2740
+ ],
2741
+ },
2742
+ 'rows' : [
2743
+ {'f' : [{'v' : 'Phred Phlyntstone' }, {'v' : '32' }]},
2744
+ {'f' : [{'v' : 'Bharney Rhubble' }, {'v' : '33' }]},
2745
+ {'f' : [{'v' : 'Wylma Phlyntstone' }, {'v' : '29' }]},
2746
+ {'f' : [{'v' : 'Bhettye Rhubble' }, {'v' : '27' }]},
2747
+ ],
2748
+ }
2749
+ done_resource = copy .deepcopy (begun_resource )
2750
+ done_resource ['status' ] = {'state' : 'DONE' }
2751
+ connection = _Connection (
2752
+ begun_resource , query_resource , done_resource , query_resource )
2753
+ client = _make_client (project = self .PROJECT , connection = connection )
2754
+ job = self ._make_one (self .JOB_ID , self .QUERY , client )
2755
+
2756
+ df = job .to_dataframe ()
2757
+
2758
+ self .assertIsInstance (df , pandas .DataFrame )
2759
+ self .assertEqual (len (df ), 4 ) # verify the number of rows
2760
+ self .assertEqual (list (df ), ['name' , 'age' ]) # verify the column names
2761
+
2727
2762
def test_iter (self ):
2728
2763
import types
2729
2764
0 commit comments