#NEWLINE# def test_aggregate_query_result_to_data_frame( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# import pandas as pd #NEWLINE# class MockSynapse ( object ) : #NEWLINE# #INDENT# def _queryTable( self , query , limit = None , offset = None , isConsistent = True , partMask = None ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'concreteType' : 'org.sagebionetworks.repo.model.table.QueryResultBundle' , #NEWLINE# 'maxRowsPerPage' : 2 , #NEWLINE# 'queryCount' : 4 , #NEWLINE# 'queryResult' : { #NEWLINE# #INDENT# 'concreteType' : 'org.sagebionetworks.repo.model.table.QueryResult' , #NEWLINE# 'nextPageToken' : 'aaaaaaaa' , #NEWLINE# 'queryResults' : { #NEWLINE# #INDENT# 'etag' : 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' , #NEWLINE# 'headers' : [ { #NEWLINE# #INDENT# 'columnType' : 'STRING' , #NEWLINE# 'name' : 'State' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'columnType' : 'INTEGER' , #NEWLINE# 'name' : 'MIN(Born)' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'columnType' : 'INTEGER' , #NEWLINE# 'name' : 'COUNT(State)' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'columnType' : 'DOUBLE' , #NEWLINE# 'name' : 'AVG(Hipness)' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'rows' : [ { #NEWLINE# #INDENT# 'values' : [ 'PA' , '1935' , '2' , '1.1' ] , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'values' : [ 'MO' , '1928' , '3' , '2.38' ] , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'tableId' : 'syn2757980' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# 'selectColumns' : [ { #NEWLINE# #INDENT# 'columnType' : 'STRING' , #NEWLINE# 'id' : '1387' , #NEWLINE# 'name' : 'State' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# def _queryTableNext( self , nextPageToken , tableId ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'concreteType' : 'org.sagebionetworks.repo.model.table.QueryResult' , #NEWLINE# 'queryResults' : { #NEWLINE# #INDENT# 'etag' : 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' , #NEWLINE# 'headers' : [ { #NEWLINE# #INDENT# 'columnType' : 'STRING' , #NEWLINE# 'name' : 'State' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'columnType' : 'INTEGER' , #NEWLINE# 'name' : 'MIN(Born)' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'columnType' : 'INTEGER' , #NEWLINE# 'name' : 'COUNT(State)' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'columnType' : 'DOUBLE' , #NEWLINE# 'name' : 'AVG(Hipness)' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'rows' : [ { #NEWLINE# #INDENT# 'values' : [ 'DC' , '1929' , '1' , '3.14' ] , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'values' : [ 'NC' , '1926' , '1' , '4.38' ] , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'tableId' : 'syn2757980' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# result = TableQueryResult ( synapse = MockSynapse ( ) , query = 'select State, min(Born), count(State), avg(Hipness) from syn2757980 group by Living' ) #NEWLINE# assert ( result . etag == 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' ) #NEWLINE# assert ( result . tableId == 'syn2757980' ) #NEWLINE# assert ( len ( result . headers ) == 4 ) #NEWLINE# rs = result . asRowSet ( ) #NEWLINE# assert ( len ( rs . rows ) == 4 ) #NEWLINE# result = TableQueryResult ( synapse = MockSynapse ( ) , query = 'select State, min(Born), count(State), avg(Hipness) from syn2757980 group by Living' ) #NEWLINE# df = result . asDataFrame ( ) #NEWLINE# assert ( df . shape == ( 4 , 4 ) ) #NEWLINE# assert all ( ( df [ 'State' ] . values == [ 'PA' , 'MO' , 'DC' , 'NC' ] ) ) #NEWLINE# assert all ( ( df [ 'MIN(Born)' ] . values == [ 1935 , 1928 , 1929 , 1926 ] ) ) , ( 'Unexpected values' + str ( df [ 'MIN(Born)' ] . values ) ) #NEWLINE# assert all ( ( df [ 'COUNT(State)' ] . values == [ 2 , 3 , 1 , 1 ] ) ) #NEWLINE# assert all ( ( result [ 'AVG(Hipness)' ] . values == [ 1.1 , 2.38 , 3.14 , 4.38 ] ) ) #NEWLINE# #UNINDENT# except ImportError as e1 : #NEWLINE# #INDENT# sys . stderr . write ( 'Pandas is apparently not installed, skipping asDataFrame portion of test_aggregate_query_result_to_data_frame.\n\n' )