@@ -124,9 +124,9 @@ def _still_in_use(bad_request):
124
124
for doomed in self .to_delete :
125
125
if isinstance (doomed , Bucket ):
126
126
retry_409 (doomed .delete )(force = True )
127
- elif isinstance (doomed , Dataset ):
127
+ elif isinstance (doomed , ( Dataset , bigquery . DatasetReference ) ):
128
128
retry_in_use (Config .CLIENT .delete_dataset )(doomed )
129
- elif isinstance (doomed , Table ):
129
+ elif isinstance (doomed , ( Table , bigquery . TableReference ) ):
130
130
retry_in_use (Config .CLIENT .delete_table )(doomed )
131
131
else :
132
132
doomed .delete ()
@@ -327,7 +327,7 @@ def _fetch_single_page(table, selected_fields=None):
327
327
page = six .next (iterator .pages )
328
328
return list (page )
329
329
330
- def test_create_rows_then_dump_table (self ):
330
+ def test_insert_rows_then_dump_table (self ):
331
331
NOW_SECONDS = 1448911495.484366
332
332
NOW = datetime .datetime .utcfromtimestamp (
333
333
NOW_SECONDS ).replace (tzinfo = UTC )
@@ -339,7 +339,7 @@ def test_create_rows_then_dump_table(self):
339
339
]
340
340
ROW_IDS = range (len (ROWS ))
341
341
342
- dataset = self .temp_dataset (_make_dataset_id ('create_rows_then_dump ' ))
342
+ dataset = self .temp_dataset (_make_dataset_id ('insert_rows_then_dump ' ))
343
343
TABLE_ID = 'test_table'
344
344
schema = [
345
345
bigquery .SchemaField ('full_name' , 'STRING' , mode = 'REQUIRED' ),
@@ -352,7 +352,7 @@ def test_create_rows_then_dump_table(self):
352
352
self .to_delete .insert (0 , table )
353
353
self .assertTrue (_table_exists (table ))
354
354
355
- errors = Config .CLIENT .create_rows (table , ROWS , row_ids = ROW_IDS )
355
+ errors = Config .CLIENT .insert_rows (table , ROWS , row_ids = ROW_IDS )
356
356
self .assertEqual (len (errors ), 0 )
357
357
358
358
rows = ()
@@ -1315,7 +1315,7 @@ def test_query_external_table(self):
1315
1315
self .assertEqual (sorted (row_tuples , key = by_age ),
1316
1316
sorted (ROWS , key = by_age ))
1317
1317
1318
- def test_create_rows_nested_nested (self ):
1318
+ def test_insert_rows_nested_nested (self ):
1319
1319
# See #2951
1320
1320
SF = bigquery .SchemaField
1321
1321
schema = [
@@ -1342,14 +1342,14 @@ def test_create_rows_nested_nested(self):
1342
1342
table = retry_403 (Config .CLIENT .create_table )(table_arg )
1343
1343
self .to_delete .insert (0 , table )
1344
1344
1345
- Config .CLIENT .create_rows (table , to_insert )
1345
+ Config .CLIENT .insert_rows (table , to_insert )
1346
1346
1347
1347
retry = RetryResult (_has_rows , max_tries = 8 )
1348
1348
rows = retry (self ._fetch_single_page )(table )
1349
1349
row_tuples = [r .values () for r in rows ]
1350
1350
self .assertEqual (row_tuples , to_insert )
1351
1351
1352
- def test_create_rows_nested_nested_dictionary (self ):
1352
+ def test_insert_rows_nested_nested_dictionary (self ):
1353
1353
# See #2951
1354
1354
SF = bigquery .SchemaField
1355
1355
schema = [
@@ -1376,7 +1376,7 @@ def test_create_rows_nested_nested_dictionary(self):
1376
1376
table = retry_403 (Config .CLIENT .create_table )(table_arg )
1377
1377
self .to_delete .insert (0 , table )
1378
1378
1379
- Config .CLIENT .create_rows (table , to_insert )
1379
+ Config .CLIENT .insert_rows (table , to_insert )
1380
1380
1381
1381
retry = RetryResult (_has_rows , max_tries = 8 )
1382
1382
rows = retry (self ._fetch_single_page )(table )
@@ -1402,7 +1402,7 @@ def test_create_table_rows_fetch_nested_schema(self):
1402
1402
for line in rows_file :
1403
1403
to_insert .append (json .loads (line ))
1404
1404
1405
- errors = Config .CLIENT .create_rows_json (table , to_insert )
1405
+ errors = Config .CLIENT .insert_rows_json (table , to_insert )
1406
1406
self .assertEqual (len (errors ), 0 )
1407
1407
1408
1408
retry = RetryResult (_has_rows , max_tries = 8 )
@@ -1467,19 +1467,24 @@ def test_nested_table_to_dataframe(self):
1467
1467
'nested_record' : {'nested_nested_string' : 'some deep insight' },
1468
1468
}
1469
1469
to_insert = [
1470
- ( ' Some value' , record )
1470
+ { 'string_col' : ' Some value' , 'record_col' : record },
1471
1471
]
1472
+ rows = [json .dumps (row ) for row in to_insert ]
1473
+ body = six .StringIO ('{}\n ' .format ('\n ' .join (rows )))
1472
1474
table_id = 'test_table'
1473
1475
dataset = self .temp_dataset (_make_dataset_id ('nested_df' ))
1474
- table_arg = Table (dataset .table (table_id ), schema = schema )
1475
- table = retry_403 (Config .CLIENT .create_table )(table_arg )
1476
+ table = dataset .table (table_id )
1476
1477
self .to_delete .insert (0 , table )
1477
- Config .CLIENT .create_rows (table , to_insert )
1478
- QUERY = 'SELECT * from `{}.{}.{}`' .format (
1479
- Config .CLIENT .project , dataset .dataset_id , table_id )
1480
-
1481
- retry = RetryResult (_has_rows , max_tries = 8 )
1482
- df = retry (self ._fetch_dataframe )(QUERY )
1478
+ job_config = bigquery .LoadJobConfig ()
1479
+ job_config .write_disposition = 'WRITE_TRUNCATE'
1480
+ job_config .source_format = 'NEWLINE_DELIMITED_JSON'
1481
+ job_config .schema = schema
1482
+ # Load a table using a local JSON file from memory.
1483
+ Config .CLIENT .load_table_from_file (
1484
+ body , table , job_config = job_config ).result ()
1485
+
1486
+ df = Config .CLIENT .list_rows (
1487
+ table , selected_fields = schema ).to_dataframe ()
1483
1488
1484
1489
self .assertIsInstance (df , pandas .DataFrame )
1485
1490
self .assertEqual (len (df ), 1 ) # verify the number of rows
0 commit comments