From 20678db492d02d8a9f97f2b6e0a4edaecaee4e14 Mon Sep 17 00:00:00 2001 From: ksindi Date: Sat, 6 Aug 2016 13:24:19 -0400 Subject: [PATCH] ENH: raise ImporError if conn is string and sqlalchemy not installed --- pandas/io/sql.py | 2 ++ pandas/io/tests/test_sql.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 49f277f6ba7bc..47642c2e2bc28 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -528,6 +528,8 @@ def pandasSQL_builder(con, flavor=None, schema=None, meta=None, con = _engine_builder(con) if _is_sqlalchemy_connectable(con): return SQLDatabase(con, schema=schema, meta=meta) + elif isinstance(con, string_types): + raise ImportError("Using URI string without sqlalchemy installed.") else: return SQLiteDatabase(con, is_cursor=is_cursor) diff --git a/pandas/io/tests/test_sql.py b/pandas/io/tests/test_sql.py index 21c3ea416e091..ffe7b9d6b460a 100644 --- a/pandas/io/tests/test_sql.py +++ b/pandas/io/tests/test_sql.py @@ -1051,6 +1051,14 @@ def test_sql_open_close(self): tm.assert_frame_equal(self.test_frame3, result) + def test_con_string_import_error(self): + if not SQLALCHEMY_INSTALLED: + conn = 'mysql://root@localhost/pandas_nosetest' + self.assertRaises(ImportError, sql.read_sql, "SELECT * FROM iris", + conn) + else: + raise nose.SkipTest('SQLAlchemy is installed') + def test_read_sql_delegate(self): iris_frame1 = sql.read_sql_query("SELECT * FROM iris", self.conn) iris_frame2 = sql.read_sql("SELECT * FROM iris", self.conn)