def test_download_all_data_types(self): # Test that all available data types from BigQuery (as of now) # are handled properly if not os.path.exists(self.bq_token): raise nose.SkipTest( 'Skipped because authentication information is not available.') query = """SELECT "PI" as VALID_STRING, "" as EMPTY_STRING, STRING(NULL) as NULL_STRING, INTEGER(3) as VALID_INTEGER, INTEGER(NULL) as NULL_INTEGER, PI() as VALID_FLOAT, FLOAT(NULL) as NULL_FLOAT, TIMESTAMP("1970-01-01 00:00:00") as UNIX_EPOCH, TIMESTAMP("2004-09-15 05:00:00") as VALID_TIMESTAMP, TIMESTAMP(NULL) as NULL_TIMESTAMP, BOOLEAN(TRUE) as TRUE_BOOLEAN, BOOLEAN(FALSE) as FALSE_BOOLEAN, BOOLEAN(NULL) as NULL_BOOLEAN""" client = gbq._authenticate() a = gbq.read_gbq(query, col_order=[ 'VALID_STRING', 'EMPTY_STRING', 'NULL_STRING', 'VALID_INTEGER', 'NULL_INTEGER', 'VALID_FLOAT', 'NULL_FLOAT', 'UNIX_EPOCH', 'VALID_TIMESTAMP', 'NULL_TIMESTAMP', 'TRUE_BOOLEAN', 'FALSE_BOOLEAN', 'NULL_BOOLEAN' ]) tm.assert_frame_equal(a, self.correct_test_datatype)
def test_table__not_exists(self): # Test the inverse of `test_table_exists` if not os.path.exists(self.bq_token): raise nose.SkipTest('Skipped because authentication information is not available.') client = gbq._authenticate() table_reference = client.GetTableReference("publicdata:samples.does_not_exist") self.assertFalse(client.TableExists(table_reference))
def test_download_dataset_larger_than_100k_rows(self): # Test for known BigQuery bug in datasets larger than 100k rows # http://stackoverflow.com/questions/19145587/bq-py-not-paging-results if not os.path.exists(self.bq_token): raise nose.SkipTest('Skipped because authentication information is not available.') client = gbq._authenticate() a = gbq.read_gbq("SELECT id, FROM [publicdata:samples.wikipedia] LIMIT 100005") self.assertTrue(len(a) == 100005)
def test_table__not_exists(self): # Test the inverse of `test_table_exists` if not os.path.exists(self.bq_token): raise nose.SkipTest( 'Skipped because authentication information is not available.') client = gbq._authenticate() table_reference = client.GetTableReference( "publicdata:samples.does_not_exist") self.assertFalse(client.TableExists(table_reference))
def test_download_dataset_larger_than_100k_rows(self): # Test for known BigQuery bug in datasets larger than 100k rows # http://stackoverflow.com/questions/19145587/bq-py-not-paging-results if not os.path.exists(self.bq_token): raise nose.SkipTest( 'Skipped because authentication information is not available.') client = gbq._authenticate() a = gbq.read_gbq( "SELECT id, FROM [publicdata:samples.wikipedia] LIMIT 100005") self.assertTrue(len(a) == 100005)
def test_table_exists(self): # Given a table name in the format {dataset}.{tablename}, if a table exists, # the GetTableReference should accurately indicate this. # This could possibly change in future implementations of bq, # but it is the simplest way to provide users with appropriate # error messages regarding schemas. if not os.path.exists(self.bq_token): raise nose.SkipTest('Skipped because authentication information is not available.') client = gbq._authenticate() table_reference = client.GetTableReference("publicdata:samples.shakespeare") self.assertTrue(client.TableExists(table_reference))
def test_table_exists(self): # Given a table name in the format {dataset}.{tablename}, if a table exists, # the GetTableReference should accurately indicate this. # This could possibly change in future implementations of bq, # but it is the simplest way to provide users with appropriate # error messages regarding schemas. if not os.path.exists(self.bq_token): raise nose.SkipTest( 'Skipped because authentication information is not available.') client = gbq._authenticate() table_reference = client.GetTableReference( "publicdata:samples.shakespeare") self.assertTrue(client.TableExists(table_reference))
def test_unicode_string_conversion(self): # Strings from BigQuery Should be converted to UTF-8 properly if not os.path.exists(self.bq_token): raise nose.SkipTest( 'Skipped because authentication information is not available.') correct_test_datatype = DataFrame({'UNICODE_STRING': [u("\xe9\xfc")]}) query = """SELECT '\xc3\xa9\xc3\xbc' as UNICODE_STRING""" client = gbq._authenticate() a = gbq.read_gbq(query) tm.assert_frame_equal(a, correct_test_datatype)
def test_unicode_string_conversion(self): # Strings from BigQuery Should be converted to UTF-8 properly if not os.path.exists(self.bq_token): raise nose.SkipTest('Skipped because authentication information is not available.') correct_test_datatype = DataFrame( {'UNICODE_STRING' : [u("\xe9\xfc")]} ) query = """SELECT '\xc3\xa9\xc3\xbc' as UNICODE_STRING""" client = gbq._authenticate() a = gbq.read_gbq(query) tm.assert_frame_equal(a, correct_test_datatype)
def test_download_all_data_types(self): # Test that all available data types from BigQuery (as of now) # are handled properly if not os.path.exists(self.bq_token): raise nose.SkipTest('Skipped because authentication information is not available.') query = """SELECT "PI" as VALID_STRING, "" as EMPTY_STRING, STRING(NULL) as NULL_STRING, INTEGER(3) as VALID_INTEGER, INTEGER(NULL) as NULL_INTEGER, PI() as VALID_FLOAT, FLOAT(NULL) as NULL_FLOAT, TIMESTAMP("1970-01-01 00:00:00") as UNIX_EPOCH, TIMESTAMP("2004-09-15 05:00:00") as VALID_TIMESTAMP, TIMESTAMP(NULL) as NULL_TIMESTAMP, BOOLEAN(TRUE) as TRUE_BOOLEAN, BOOLEAN(FALSE) as FALSE_BOOLEAN, BOOLEAN(NULL) as NULL_BOOLEAN""" client = gbq._authenticate() a = gbq.read_gbq(query, col_order = ['VALID_STRING', 'EMPTY_STRING', 'NULL_STRING', 'VALID_INTEGER', 'NULL_INTEGER', 'VALID_FLOAT', 'NULL_FLOAT', 'UNIX_EPOCH', 'VALID_TIMESTAMP', 'NULL_TIMESTAMP', 'TRUE_BOOLEAN', 'FALSE_BOOLEAN', 'NULL_BOOLEAN']) tm.assert_frame_equal(a, self.correct_test_datatype)