Skip to content

Commit 9a93811

Browse files
committed
Adjust SQL tests
1 parent 4319527 commit 9a93811

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

pandas/core/tools/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def _convert_listlike(arg, box, format, name=None, tz=tz):
457457
if is_datetime64_dtype(result) and box:
458458
result = DatetimeIndex(result, tz=tz, name=name)
459459
# GH 6415
460-
elif arg_is_series:
460+
elif arg_is_series and utc:
461461
result = _maybe_convert_to_utc(Series(result, name=name), utc)
462462
return result
463463

pandas/tests/io/test_sql.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def test_execute_sql(self):
602602
tm.equalContents(row, [5.1, 3.5, 1.4, 0.2, 'Iris-setosa'])
603603

604604
def test_date_parsing(self):
605-
# Test date parsing in read_sq
605+
# Test date parsing in read_sql
606606
# No Parsing
607607
df = sql.read_sql_query("SELECT * FROM types_test_data", self.conn)
608608
assert not issubclass(df.DateCol.dtype.type, np.datetime64)
@@ -1248,7 +1248,9 @@ def test_default_date_load(self):
12481248

12491249
# IMPORTANT - sqlite has no native date type, so shouldn't parse, but
12501250
# 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)
12521254

12531255
def test_datetime_with_timezone(self):
12541256
# edge case that converts postgresql datetime with time zone types
@@ -1333,7 +1335,7 @@ def test_date_parsing(self):
13331335

13341336
df = sql.read_sql_table("types_test_data", self.conn, parse_dates={
13351337
'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)
13371339

13381340
df = sql.read_sql_table(
13391341
"types_test_data", self.conn, parse_dates=['IntDateCol'])
@@ -1355,7 +1357,11 @@ def test_datetime(self):
13551357
# with read_table -> type information from schema used
13561358
result = sql.read_sql_table('test_datetime', self.conn)
13571359
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)
13591365

13601366
# with read_sql -> no type information -> sqlite has no native
13611367
result = sql.read_sql_query('SELECT * FROM test_datetime', self.conn)
@@ -1375,7 +1381,11 @@ def test_datetime_NaT(self):
13751381

13761382
# with read_table -> type information from schema used
13771383
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)
13791389

13801390
# with read_sql -> no type information -> sqlite has no native
13811391
result = sql.read_sql_query('SELECT * FROM test_datetime', self.conn)
@@ -1391,8 +1401,8 @@ def test_datetime_date(self):
13911401
df = DataFrame([date(2014, 1, 1), date(2014, 1, 2)], columns=["a"])
13921402
df.to_sql('test_date', self.conn, index=False)
13931403
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))
13961406

13971407
def test_datetime_time(self):
13981408
# test support for datetime.time

0 commit comments

Comments
 (0)