|
26 | 26 | import nose
|
27 | 27 | import warnings
|
28 | 28 | import numpy as np
|
| 29 | +import pandas as pd |
29 | 30 |
|
30 | 31 | from datetime import datetime, date, time
|
31 | 32 |
|
32 | 33 | from pandas import DataFrame, Series, Index, MultiIndex, isnull, concat
|
33 | 34 | from pandas import date_range, to_datetime, to_timedelta, Timestamp
|
34 | 35 | import pandas.compat as compat
|
35 | 36 | from pandas.compat import StringIO, range, lrange, string_types
|
| 37 | +from pandas.core import common as com |
36 | 38 | from pandas.core.datetools import format as date_format
|
37 | 39 |
|
38 | 40 | import pandas.io.sql as sql
|
@@ -1248,6 +1250,39 @@ def test_default_date_load(self):
|
1248 | 1250 | self.assertTrue(issubclass(df.DateCol.dtype.type, np.datetime64),
|
1249 | 1251 | "DateCol loaded with incorrect type")
|
1250 | 1252 |
|
| 1253 | + def test_datetime_with_timezone(self): |
| 1254 | + # edge case that converts postgresql datetime with time zone types |
| 1255 | + # to datetime64[ns,psycopg2.tz.FixedOffsetTimezone..], which is ok |
| 1256 | + # but should be more natural, so coerce to datetime64[ns] for now |
| 1257 | + |
| 1258 | + # GH11216 |
| 1259 | + df = pd.read_sql_query("select * from types_test_data", self.conn) |
| 1260 | + if not hasattr(df,'DateColWithTz'): |
| 1261 | + raise nose.SkipTest("no column with datetime with time zone") |
| 1262 | + |
| 1263 | + # this is parsed on Travis (linux), but not on macosx for some reason |
| 1264 | + # even with the same versions of psycopg2 & sqlalchemy, possibly a Postgrsql server |
| 1265 | + # version difference |
| 1266 | + dtype = df.DateColWithTz.dtype |
| 1267 | + self.assertTrue(com.is_object_dtype(dtype) or com.is_datetime64_dtype(dtype), |
| 1268 | + "DateCol loaded with incorrect type -> {0}".format(dtype)) |
| 1269 | + |
| 1270 | + df = pd.read_sql_query("select * from types_test_data", self.conn, parse_dates=['DateColWithTz']) |
| 1271 | + if not hasattr(df,'DateColWithTz'): |
| 1272 | + raise nose.SkipTest("no column with datetime with time zone") |
| 1273 | + |
| 1274 | + dtype = df.DateColWithTz.dtype |
| 1275 | + self.assertTrue(com.is_datetime64_dtype(dtype), |
| 1276 | + "DateCol loaded with incorrect type -> {0}".format(dtype)) |
| 1277 | + |
| 1278 | + df = pd.concat(list(pd.read_sql_query("select * from types_test_data", |
| 1279 | + self.conn,chunksize=1)),ignore_index=True) |
| 1280 | + dtype = df.DateColWithTz.dtype |
| 1281 | + self.assertTrue(com.is_datetime64_dtype(dtype), |
| 1282 | + "DateCol loaded with incorrect type -> {0}".format(dtype)) |
| 1283 | + expected = sql.read_sql_table("types_test_data", self.conn) |
| 1284 | + tm.assert_series_equal(df.DateColWithTz, expected.DateColWithTz) |
| 1285 | + |
1251 | 1286 | def test_date_parsing(self):
|
1252 | 1287 | # No Parsing
|
1253 | 1288 | df = sql.read_sql_table("types_test_data", self.conn)
|
|
0 commit comments