@@ -602,7 +602,7 @@ def test_execute_sql(self):
602
602
tm .equalContents (row , [5.1 , 3.5 , 1.4 , 0.2 , 'Iris-setosa' ])
603
603
604
604
def test_date_parsing (self ):
605
- # Test date parsing in read_sq
605
+ # Test date parsing in read_sql
606
606
# No Parsing
607
607
df = sql .read_sql_query ("SELECT * FROM types_test_data" , self .conn )
608
608
assert not issubclass (df .DateCol .dtype .type , np .datetime64 )
@@ -1248,7 +1248,9 @@ def test_default_date_load(self):
1248
1248
1249
1249
# IMPORTANT - sqlite has no native date type, so shouldn't parse, but
1250
1250
# MySQL SHOULD be converted.
1251
- assert issubclass (df .DateCol .dtype .type , np .datetime64 )
1251
+ # Now that GH 6415 is fixed, dates are automatically parsed to UTC
1252
+ utc_dtype = pd .core .dtypes .dtypes .DatetimeTZDtypeType
1253
+ assert issubclass (df .DateCol .dtype .type , utc_dtype )
1252
1254
1253
1255
def test_datetime_with_timezone (self ):
1254
1256
# edge case that converts postgresql datetime with time zone types
@@ -1333,7 +1335,7 @@ def test_date_parsing(self):
1333
1335
1334
1336
df = sql .read_sql_table ("types_test_data" , self .conn , parse_dates = {
1335
1337
'DateCol' : {'format' : '%Y-%m-%d %H:%M:%S' }})
1336
- assert issubclass (df .DateCol .dtype .type , utc_dtype )
1338
+ assert issubclass (df .DateCol .dtype .type , np . datetime64 )
1337
1339
1338
1340
df = sql .read_sql_table (
1339
1341
"types_test_data" , self .conn , parse_dates = ['IntDateCol' ])
@@ -1355,7 +1357,11 @@ def test_datetime(self):
1355
1357
# with read_table -> type information from schema used
1356
1358
result = sql .read_sql_table ('test_datetime' , self .conn )
1357
1359
result = result .drop ('index' , axis = 1 )
1358
- tm .assert_frame_equal (result , df )
1360
+ # After GH 6415, dates outbound from a db will be localized to UTC
1361
+ # xref GH 7364
1362
+ expected = df .copy ()
1363
+ expected ['A' ] = expected ['A' ].dt .tz_localize ('UTC' )
1364
+ tm .assert_frame_equal (result , expected )
1359
1365
1360
1366
# with read_sql -> no type information -> sqlite has no native
1361
1367
result = sql .read_sql_query ('SELECT * FROM test_datetime' , self .conn )
@@ -1375,7 +1381,11 @@ def test_datetime_NaT(self):
1375
1381
1376
1382
# with read_table -> type information from schema used
1377
1383
result = sql .read_sql_table ('test_datetime' , self .conn )
1378
- tm .assert_frame_equal (result , df )
1384
+ # After GH 6415, dates outbound from a db will be localized to UTC
1385
+ # xref GH 7364
1386
+ expected = df .copy ()
1387
+ expected ['A' ] = expected ['A' ].dt .tz_localize ('UTC' )
1388
+ tm .assert_frame_equal (result , expected )
1379
1389
1380
1390
# with read_sql -> no type information -> sqlite has no native
1381
1391
result = sql .read_sql_query ('SELECT * FROM test_datetime' , self .conn )
@@ -1391,8 +1401,8 @@ def test_datetime_date(self):
1391
1401
df = DataFrame ([date (2014 , 1 , 1 ), date (2014 , 1 , 2 )], columns = ["a" ])
1392
1402
df .to_sql ('test_date' , self .conn , index = False )
1393
1403
res = read_sql_table ('test_date' , self .conn )
1394
- # comes back as datetime64
1395
- tm .assert_series_equal (res ['a' ], to_datetime (df ['a' ]))
1404
+ # GH 6415 comes back as datetime64[ns, UTC]
1405
+ tm .assert_series_equal (res ['a' ], to_datetime (df ['a' ], utc = True ))
1396
1406
1397
1407
def test_datetime_time (self ):
1398
1408
# test support for datetime.time
0 commit comments