1
1
# -*- coding: utf-8 -*-
2
2
3
3
import sys
4
- from datetime import datetime
5
4
import uuid
5
+ from datetime import datetime
6
6
7
7
import numpy as np
8
8
import pandas .util .testing as tm
@@ -200,9 +200,7 @@ def test_should_properly_handle_nullable_integers(self, project_id):
200
200
private_key = self .credentials ,
201
201
dialect = "legacy" ,
202
202
)
203
- tm .assert_frame_equal (
204
- df , DataFrame ({"nullable_integer" : [1 , None ]}).astype (object )
205
- )
203
+ tm .assert_frame_equal (df , DataFrame ({"nullable_integer" : [1 , None ]}))
206
204
207
205
def test_should_properly_handle_valid_longs (self , project_id ):
208
206
query = "SELECT 1 << 62 AS valid_long"
@@ -225,7 +223,7 @@ def test_should_properly_handle_nullable_longs(self, project_id):
225
223
dialect = "legacy" ,
226
224
)
227
225
tm .assert_frame_equal (
228
- df , DataFrame ({"nullable_long" : [1 << 62 , None ]}). astype ( object )
226
+ df , DataFrame ({"nullable_long" : [1 << 62 , None ]})
229
227
)
230
228
231
229
def test_should_properly_handle_null_integers (self , project_id ):
@@ -338,35 +336,43 @@ def test_should_properly_handle_arbitrary_timestamp(self, project_id):
338
336
),
339
337
)
340
338
341
- def test_should_properly_handle_null_timestamp (self , project_id ):
342
- query = "SELECT TIMESTAMP(NULL) AS null_timestamp"
343
- df = gbq .read_gbq (
344
- query ,
345
- project_id = project_id ,
346
- private_key = self .credentials ,
347
- dialect = "legacy" ,
348
- )
349
- tm .assert_frame_equal (df , DataFrame ({"null_timestamp" : [NaT ]}))
339
+ @pytest .mark .parametrize (
340
+ "expression, type_" ,
341
+ [
342
+ ("current_date()" , "<M8[ns]" ),
343
+ ("current_timestamp()" , "<M8[ns]" ),
344
+ ("current_datetime()" , "<M8[ns]" ),
345
+ ("TRUE" , bool ),
346
+ ("FALSE" , bool ),
347
+ ],
348
+ )
349
+ def test_return_correct_types (self , project_id , expression , type_ ):
350
+ """
351
+ All type checks can be added to this function using additional
352
+ parameters, rather than creating additional functions.
353
+ We can consolidate the existing functions here in time
350
354
351
- def test_should_properly_handle_true_boolean (self , project_id ):
352
- query = "SELECT BOOLEAN(TRUE) AS true_boolean"
355
+ TODO: time doesn't currently parse
356
+ ("time(12,30,00)", "<M8[ns]"),
357
+ """
358
+ query = "SELECT {} AS _" .format (expression )
353
359
df = gbq .read_gbq (
354
360
query ,
355
361
project_id = project_id ,
356
362
private_key = self .credentials ,
357
- dialect = "legacy " ,
363
+ dialect = "standard " ,
358
364
)
359
- tm . assert_frame_equal ( df , DataFrame ({ "true_boolean" : [ True ]}))
365
+ assert df [ "_" ]. dtype == type_
360
366
361
- def test_should_properly_handle_false_boolean (self , project_id ):
362
- query = "SELECT BOOLEAN(FALSE ) AS false_boolean "
367
+ def test_should_properly_handle_null_timestamp (self , project_id ):
368
+ query = "SELECT TIMESTAMP(NULL ) AS null_timestamp "
363
369
df = gbq .read_gbq (
364
370
query ,
365
371
project_id = project_id ,
366
372
private_key = self .credentials ,
367
373
dialect = "legacy" ,
368
374
)
369
- tm .assert_frame_equal (df , DataFrame ({"false_boolean " : [False ]}))
375
+ tm .assert_frame_equal (df , DataFrame ({"null_timestamp " : [NaT ]}))
370
376
371
377
def test_should_properly_handle_null_boolean (self , project_id ):
372
378
query = "SELECT BOOLEAN(NULL) AS null_boolean"
0 commit comments