File tree 2 files changed +8
-5
lines changed
2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -738,12 +738,14 @@ def pandasSQL_builder(con, schema: str | None = None):
738
738
739
739
sqlalchemy = import_optional_dependency ("sqlalchemy" , errors = "ignore" )
740
740
741
- if sqlalchemy is not None :
742
- if isinstance (con , str ):
741
+ if isinstance (con , str ):
742
+ if sqlalchemy is None :
743
+ raise ImportError ("Using URI string without sqlalchemy installed." )
744
+ else :
743
745
con = sqlalchemy .create_engine (con )
744
746
745
- if isinstance (con , sqlalchemy .engine .Connectable ):
746
- return SQLDatabase (con , schema = schema )
747
+ if sqlalchemy is not None and isinstance (con , sqlalchemy .engine .Connectable ):
748
+ return SQLDatabase (con , schema = schema )
747
749
748
750
warnings .warn (
749
751
"pandas only support SQLAlchemy connectable(engine/connection) or"
Original file line number Diff line number Diff line change @@ -1524,7 +1524,8 @@ def test_sql_open_close(self, test_frame3):
1524
1524
@pytest .mark .skipif (SQLALCHEMY_INSTALLED , reason = "SQLAlchemy is installed" )
1525
1525
def test_con_string_import_error (self ):
1526
1526
conn = "mysql://root@localhost/pandas"
1527
- with pytest .raises (ImportError , match = "SQLAlchemy" ):
1527
+ msg = "Using URI string without sqlalchemy installed"
1528
+ with pytest .raises (ImportError , match = msg ):
1528
1529
sql .read_sql ("SELECT * FROM iris" , conn )
1529
1530
1530
1531
@pytest .mark .skipif (SQLALCHEMY_INSTALLED , reason = "SQLAlchemy is installed" )
You can’t perform that action at this time.
0 commit comments