9
9
import os
10
10
from random import randint
11
11
import logging
12
+ import sys
12
13
13
14
import numpy as np
14
15
@@ -1161,25 +1162,33 @@ def test_upload_chinese_unicode_data(self):
1161
1162
test_size = 6
1162
1163
df = DataFrame (np .random .randn (6 , 4 ), index = range (6 ),
1163
1164
columns = list ('ABCD' ))
1164
- df . A = u'信用卡'
1165
+ df [ 's' ] = u'信用卡'
1165
1166
1166
1167
gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
1167
1168
chunksize = 10000 )
1168
1169
1169
- result = gbq .read_gbq ("SELECT COUNT(*) AS num_rows FROM {0}" .format (
1170
+ result = gbq .read_gbq ("SELECT * FROM {0}" .format (
1170
1171
self .destination_table + test_id ),
1171
1172
project_id = _get_project_id ())
1172
1173
1173
- assert result ['num_rows' ][0 ] == test_size
1174
- tm .assert_series_equal (result ['A' ], df ['A' ])
1174
+ assert len (result_df ) == test_size
1175
+
1176
+ pytest .skipif (
1177
+ sys .version_info .major < 3 ,
1178
+ reason = 'Unicode comparison in Py2 not working' )
1179
+
1180
+ result = result_df ['s' ].sort_values ()
1181
+ expected = df ['s' ].sort_values ()
1182
+
1183
+ tm .assert_numpy_array_equal (expected .values , result .values )
1175
1184
1176
1185
def test_upload_other_unicode_data (self ):
1177
1186
test_id = "3"
1178
1187
test_size = 3
1179
1188
df = DataFrame ({
1180
- 'string ' : ['Skywalker™' , 'lego' , 'hülle' ],
1181
- 'integer ' : [200 , 300 , 400 ],
1182
- 'Date ' : [
1189
+ 's ' : ['Skywalker™' , 'lego' , 'hülle' ],
1190
+ 'i ' : [200 , 300 , 400 ],
1191
+ 'd ' : [
1183
1192
'2017-12-13 17:40:39' , '2017-12-13 17:40:39' ,
1184
1193
'2017-12-13 17:40:39'
1185
1194
]
@@ -1188,12 +1197,20 @@ def test_upload_other_unicode_data(self):
1188
1197
gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
1189
1198
chunksize = 10000 )
1190
1199
1191
- result = gbq .read_gbq ("SELECT COUNT(*) AS num_rows FROM {0}" .format (
1200
+ result_df = gbq .read_gbq ("SELECT * FROM {0}" .format (
1192
1201
self .destination_table + test_id ),
1193
1202
project_id = _get_project_id ())
1194
1203
1195
- assert result ['num_rows' ][0 ] == test_size
1196
- tm .assert_series_equal (result ['string' ], df ['string' ])
1204
+ assert len (result_df ) == test_size
1205
+
1206
+ pytest .skipif (
1207
+ sys .version_info .major < 3 ,
1208
+ reason = 'Unicode comparison in Py2 not working' )
1209
+
1210
+ result = result_df ['s' ].sort_values ()
1211
+ expected = df ['s' ].sort_values ()
1212
+
1213
+ tm .assert_numpy_array_equal (expected .values , result .values )
1197
1214
1198
1215
def test_generate_schema (self ):
1199
1216
df = tm .makeMixedDataFrame ()
@@ -1513,25 +1530,32 @@ def test_upload_chinese_unicode_data(self):
1513
1530
test_size = 6
1514
1531
df = DataFrame (np .random .randn (6 , 4 ), index = range (6 ),
1515
1532
columns = list ('ABCD' ))
1516
- df . A = u'信用卡'
1533
+ df [ 's' ] = u'信用卡'
1517
1534
1518
1535
gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
1519
1536
chunksize = 10000 )
1520
1537
1521
- result = gbq .read_gbq ("SELECT COUNT(*) AS num_rows FROM {0}" .format (
1538
+ result_df = gbq .read_gbq ("SELECT * FROM {0}" .format (
1522
1539
self .destination_table + test_id ),
1523
1540
project_id = _get_project_id ())
1524
1541
1525
- assert result ['num_rows' ][0 ] == test_size
1526
- tm .assert_series_equal (result ['A' ], df ['A' ])
1542
+ assert len (result_df ) == test_size
1543
+
1544
+ if sys .version_info .major < 3 :
1545
+ pytest .skip (msg = 'Unicode comparison in Py2 not working' )
1546
+
1547
+ result = result_df ['s' ].sort_values ()
1548
+ expected = df ['s' ].sort_values ()
1549
+
1550
+ tm .assert_numpy_array_equal (expected .values , result .values )
1527
1551
1528
1552
def test_upload_other_unicode_data (self ):
1529
1553
test_id = "3"
1530
1554
test_size = 3
1531
1555
df = DataFrame ({
1532
- 'string ' : ['Skywalker™' , 'lego' , 'hülle' ],
1533
- 'integer ' : [200 , 300 , 400 ],
1534
- 'Date ' : [
1556
+ 's ' : ['Skywalker™' , 'lego' , 'hülle' ],
1557
+ 'i ' : [200 , 300 , 400 ],
1558
+ 'd ' : [
1535
1559
'2017-12-13 17:40:39' , '2017-12-13 17:40:39' ,
1536
1560
'2017-12-13 17:40:39'
1537
1561
]
@@ -1540,12 +1564,20 @@ def test_upload_other_unicode_data(self):
1540
1564
gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
1541
1565
chunksize = 10000 )
1542
1566
1543
- result = gbq .read_gbq ("SELECT COUNT(*) AS num_rows FROM {0}" .format (
1567
+ result_df = gbq .read_gbq ("SELECT * FROM {0}" .format (
1544
1568
self .destination_table + test_id ),
1545
1569
project_id = _get_project_id ())
1546
1570
1547
- assert result ['num_rows' ][0 ] == test_size
1548
- tm .assert_series_equal (result ['string' ], df ['string' ])
1571
+ assert len (result_df ) == test_size
1572
+
1573
+ if sys .version_info .major < 3 :
1574
+ pytest .skip (msg = 'Unicode comparison in Py2 not working' )
1575
+
1576
+ result = result_df ['s' ].sort_values ()
1577
+ expected = df ['s' ].sort_values ()
1578
+
1579
+ tm .assert_numpy_array_equal (expected .values , result .values )
1580
+
1549
1581
1550
1582
class TestToGBQIntegrationWithServiceAccountKeyContents (object ):
1551
1583
# Changes to BigQuery table schema may take up to 2 minutes as of May 2015
0 commit comments