Skip to content

Commit cce7993

Browse files
ksindijorisvandenbossche
authored andcommitted
ENH: raise ImporError if conn is string and sqlalchemy not installed (pandas-dev#11920)
1 parent e89a0a0 commit cce7993

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pandas/io/sql.py

+2
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ def pandasSQL_builder(con, flavor=None, schema=None, meta=None,
528528
con = _engine_builder(con)
529529
if _is_sqlalchemy_connectable(con):
530530
return SQLDatabase(con, schema=schema, meta=meta)
531+
elif isinstance(con, string_types):
532+
raise ImportError("Using URI string without sqlalchemy installed.")
531533
else:
532534
return SQLiteDatabase(con, is_cursor=is_cursor)
533535

pandas/io/tests/test_sql.py

+8
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,14 @@ def test_sql_open_close(self):
10511051

10521052
tm.assert_frame_equal(self.test_frame3, result)
10531053

1054+
def test_con_string_import_error(self):
1055+
if not SQLALCHEMY_INSTALLED:
1056+
conn = 'mysql://root@localhost/pandas_nosetest'
1057+
self.assertRaises(ImportError, sql.read_sql, "SELECT * FROM iris",
1058+
conn)
1059+
else:
1060+
raise nose.SkipTest('SQLAlchemy is installed')
1061+
10541062
def test_read_sql_delegate(self):
10551063
iris_frame1 = sql.read_sql_query("SELECT * FROM iris", self.conn)
10561064
iris_frame2 = sql.read_sql("SELECT * FROM iris", self.conn)

0 commit comments

Comments
 (0)