diff --git a/ci/requirements-2.7.txt b/ci/requirements-2.7.txt index 8fc289b5e1511..030dae3c50fe8 100644 --- a/ci/requirements-2.7.txt +++ b/ci/requirements-2.7.txt @@ -18,4 +18,5 @@ beautifulsoup4==4.2.1 statsmodels==0.5.0 bigquery==2.0.17 sqlalchemy==0.8.1 +pymysql==0.6.1 psycopg2==2.5.2 diff --git a/ci/requirements-3.3.txt b/ci/requirements-3.3.txt index 8e85c1108b5bf..d37bc35902976 100644 --- a/ci/requirements-3.3.txt +++ b/ci/requirements-3.3.txt @@ -16,4 +16,5 @@ scipy==0.12.0 beautifulsoup4==4.2.1 statsmodels==0.4.3 sqlalchemy==0.9.1 +pymysql==0.6.1 psycopg2==2.5.2 diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 4c0c18a0e7bd0..4c0c22da63848 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -668,7 +668,7 @@ def read_table(self, table_name, index_col=None, coerce_float=True, parse_dates=None, columns=None): table = PandasSQLTable(table_name, self, index=index_col) - return table.read(coerce_float=parse_dates, + return table.read(coerce_float=coerce_float, parse_dates=parse_dates, columns=columns) def drop_table(self, table_name): diff --git a/pandas/io/tests/test_sql.py b/pandas/io/tests/test_sql.py index 0e26a66921df4..46b5758904315 100644 --- a/pandas/io/tests/test_sql.py +++ b/pandas/io/tests/test_sql.py @@ -495,7 +495,7 @@ def test_read_table_absent(self): self.assertRaises( ValueError, sql.read_table, "this_doesnt_exist", con=self.conn) - def test_default_type_convertion(self): + def test_default_type_conversion(self): df = sql.read_table("types_test_data", self.conn) self.assertTrue(issubclass(df.FloatCol.dtype.type, np.floating), @@ -589,7 +589,7 @@ def setUp(self): self._load_test1_data() - def test_default_type_convertion(self): + def test_default_type_conversion(self): df = sql.read_table("types_test_data", self.conn) self.assertTrue(issubclass(df.FloatCol.dtype.type, np.floating), @@ -755,6 +755,24 @@ def tearDown(self): for table in c.fetchall(): self.conn.execute('DROP TABLE %s' % table[0]) + def test_default_type_conversion(self): + df = sql.read_table("types_test_data", self.conn) + + self.assertTrue(issubclass(df.FloatCol.dtype.type, np.floating), + "FloatCol loaded with incorrect type") + self.assertTrue(issubclass(df.IntCol.dtype.type, np.integer), + "IntCol loaded with incorrect type") + # MySQL has no real BOOL type (it's an alias for TINYINT) + self.assertTrue(issubclass(df.BoolCol.dtype.type, np.integer), + "BoolCol loaded with incorrect type") + + # Int column with NA values stays as float + self.assertTrue(issubclass(df.IntColWithNull.dtype.type, np.floating), + "IntColWithNull loaded with incorrect type") + # Bool column with NA = int column with NA values => becomes float + self.assertTrue(issubclass(df.BoolColWithNull.dtype.type, np.floating), + "BoolColWithNull loaded with incorrect type") + class TestPostgreSQLAlchemy(_TestSQLAlchemy): flavor = 'postgresql'