11# -*- coding: utf-8 -*-
22
33import sys
4- from datetime import datetime
54import uuid
5+ from datetime import datetime
66
77import numpy as np
88import pandas .util .testing as tm
@@ -200,9 +200,7 @@ def test_should_properly_handle_nullable_integers(self, project_id):
200200 private_key = self .credentials ,
201201 dialect = "legacy" ,
202202 )
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 ]}))
206204
207205 def test_should_properly_handle_valid_longs (self , project_id ):
208206 query = "SELECT 1 << 62 AS valid_long"
@@ -225,7 +223,7 @@ def test_should_properly_handle_nullable_longs(self, project_id):
225223 dialect = "legacy" ,
226224 )
227225 tm .assert_frame_equal (
228- df , DataFrame ({"nullable_long" : [1 << 62 , None ]}). astype ( object )
226+ df , DataFrame ({"nullable_long" : [1 << 62 , None ]})
229227 )
230228
231229 def test_should_properly_handle_null_integers (self , project_id ):
@@ -338,35 +336,43 @@ def test_should_properly_handle_arbitrary_timestamp(self, project_id):
338336 ),
339337 )
340338
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
350354
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 )
353359 df = gbq .read_gbq (
354360 query ,
355361 project_id = project_id ,
356362 private_key = self .credentials ,
357- dialect = "legacy " ,
363+ dialect = "standard " ,
358364 )
359- tm . assert_frame_equal ( df , DataFrame ({ "true_boolean" : [ True ]}))
365+ assert df [ "_" ]. dtype == type_
360366
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 "
363369 df = gbq .read_gbq (
364370 query ,
365371 project_id = project_id ,
366372 private_key = self .credentials ,
367373 dialect = "legacy" ,
368374 )
369- tm .assert_frame_equal (df , DataFrame ({"false_boolean " : [False ]}))
375+ tm .assert_frame_equal (df , DataFrame ({"null_timestamp " : [NaT ]}))
370376
371377 def test_should_properly_handle_null_boolean (self , project_id ):
372378 query = "SELECT BOOLEAN(NULL) AS null_boolean"
0 commit comments