|
36 | 36 | `PetalLength` DOUBLE,
|
37 | 37 | `PetalWidth` DOUBLE,
|
38 | 38 | `Name` VARCHAR(200)
|
| 39 | + )""", |
| 40 | + 'postgresql': """CREATE TABLE iris ( |
| 41 | + "SepalLength" DOUBLE PRECISION, |
| 42 | + "SepalWidth" DOUBLE PRECISION, |
| 43 | + "PetalLength" DOUBLE PRECISION, |
| 44 | + "PetalWidth" DOUBLE PRECISION, |
| 45 | + "Name" VARCHAR(200) |
39 | 46 | )"""
|
40 | 47 | },
|
41 | 48 | 'insert_iris': {
|
42 | 49 | 'sqlite': """INSERT INTO iris VALUES(?, ?, ?, ?, ?)""",
|
43 |
| - 'mysql': """INSERT INTO iris VALUES(%s, %s, %s, %s, "%s");""" |
| 50 | + 'mysql': """INSERT INTO iris VALUES(%s, %s, %s, %s, "%s");""", |
| 51 | + 'postgresql': """INSERT INTO iris VALUES(%s, %s, %s, %s, %s);""" |
44 | 52 | },
|
45 | 53 | 'create_test_types': {
|
46 | 54 | 'sqlite': """CREATE TABLE types_test_data (
|
|
62 | 70 | `BoolCol` BOOLEAN,
|
63 | 71 | `IntColWithNull` INTEGER,
|
64 | 72 | `BoolColWithNull` BOOLEAN
|
| 73 | + )""", |
| 74 | + 'postgresql': """CREATE TABLE types_test_data ( |
| 75 | + "TextCol" TEXT, |
| 76 | + "DateCol" TIMESTAMP, |
| 77 | + "IntDateCol" INTEGER, |
| 78 | + "FloatCol" DOUBLE PRECISION, |
| 79 | + "IntCol" INTEGER, |
| 80 | + "BoolCol" BOOLEAN, |
| 81 | + "IntColWithNull" INTEGER, |
| 82 | + "BoolColWithNull" BOOLEAN |
65 | 83 | )"""
|
66 | 84 | },
|
67 | 85 | 'insert_test_types': {
|
|
72 | 90 | 'mysql': """
|
73 | 91 | INSERT INTO types_test_data
|
74 | 92 | VALUES("%s", %s, %s, %s, %s, %s, %s, %s)
|
| 93 | + """, |
| 94 | + 'postgresql': """ |
| 95 | + INSERT INTO types_test_data |
| 96 | + VALUES(%s, %s, %s, %s, %s, %s, %s, %s) |
75 | 97 | """
|
76 | 98 | }
|
77 | 99 | }
|
@@ -504,8 +526,8 @@ def test_default_type_convertion(self):
|
504 | 526 | self.assertTrue(issubclass(df.IntColWithNull.dtype.type, np.floating),
|
505 | 527 | "IntColWithNull loaded with incorrect type")
|
506 | 528 | # Non-native Bool column with NA values stays as float
|
507 |
| - self.assertTrue( |
508 |
| - issubclass(df.BoolColWithNull.dtype.type, np.floating), "BoolCol loaded with incorrect type") |
| 529 | + self.assertTrue(issubclass(df.BoolColWithNull.dtype.type, np.floating), |
| 530 | + "BoolColWithNull loaded with incorrect type") |
509 | 531 |
|
510 | 532 | def test_default_date_load(self):
|
511 | 533 | df = sql.read_table("types_test_data", self.conn)
|
@@ -699,6 +721,48 @@ def test_default_date_load(self):
|
699 | 721 | self.assertTrue(
|
700 | 722 | issubclass(df.DateCol.dtype.type, np.datetime64), "DateCol loaded with incorrect type")
|
701 | 723 |
|
| 724 | + |
| 725 | +class TestPostgreSQLAlchemy(TestSQLAlchemy): |
| 726 | + flavor = 'postgresql' |
| 727 | + |
| 728 | + def connect(self): |
| 729 | + return sqlalchemy.create_engine( |
| 730 | + 'postgresql+{driver}://postgres@localhost/pandas_nosetest'.format(driver=self.driver)) |
| 731 | + |
| 732 | + def setUp(self): |
| 733 | + if not SQLALCHEMY_INSTALLED: |
| 734 | + raise nose.SkipTest('SQLAlchemy not installed') |
| 735 | + |
| 736 | + try: |
| 737 | + import psycopg2 |
| 738 | + self.driver = 'psycopg2' |
| 739 | + |
| 740 | + except ImportError: |
| 741 | + raise nose.SkipTest |
| 742 | + |
| 743 | + self.conn = self.connect() |
| 744 | + self.pandasSQL = sql.PandasSQLAlchemy(self.conn) |
| 745 | + |
| 746 | + self._load_iris_data() |
| 747 | + self._load_raw_sql() |
| 748 | + |
| 749 | + self._load_test1_data() |
| 750 | + |
| 751 | + def tearDown(self): |
| 752 | + c = self.conn.execute( |
| 753 | + "SELECT table_name FROM information_schema.tables" |
| 754 | + " WHERE table_schema = 'public'") |
| 755 | + for table in c.fetchall(): |
| 756 | + self.conn.execute("DROP TABLE %s" % table[0]) |
| 757 | + |
| 758 | + def test_default_date_load(self): |
| 759 | + df = sql.read_table("types_test_data", self.conn) |
| 760 | + |
| 761 | + # IMPORTANT - sqlite has no native date type, so shouldn't parse, |
| 762 | + # but PostgreSQL SHOULD be converted. |
| 763 | + self.assertTrue(issubclass(df.DateCol.dtype.type, np.datetime64), |
| 764 | + "DateCol loaded with incorrect type") |
| 765 | + |
702 | 766 | if __name__ == '__main__':
|
703 | 767 | nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
|
704 | 768 | exit=False)
|
0 commit comments