5858 SQLAlchemyEngine ,
5959 SQLDatabase ,
6060 SQLiteDatabase ,
61- _gt14 ,
6261 get_engine ,
6362 pandasSQL_builder ,
6463 read_sql_query ,
@@ -385,10 +384,10 @@ def mysql_pymysql_engine(iris_path, types_data):
385384 "mysql+pymysql://root@localhost:3306/pandas" ,
386385 connect_args = {"client_flag" : pymysql .constants .CLIENT .MULTI_STATEMENTS },
387386 )
388- check_target = sqlalchemy .inspect (engine ) if _gt14 () else engine
389- if not check_target .has_table ("iris" ):
387+ insp = sqlalchemy .inspect (engine )
388+ if not insp .has_table ("iris" ):
390389 create_and_load_iris (engine , iris_path , "mysql" )
391- if not check_target .has_table ("types" ):
390+ if not insp .has_table ("types" ):
392391 for entry in types_data :
393392 entry .pop ("DateColWithTz" )
394393 create_and_load_types (engine , types_data , "mysql" )
@@ -412,10 +411,10 @@ def postgresql_psycopg2_engine(iris_path, types_data):
412411 engine = sqlalchemy .create_engine (
413412 "postgresql+psycopg2://postgres:postgres@localhost:5432/pandas"
414413 )
415- check_target = sqlalchemy .inspect (engine ) if _gt14 () else engine
416- if not check_target .has_table ("iris" ):
414+ insp = sqlalchemy .inspect (engine )
415+ if not insp .has_table ("iris" ):
417416 create_and_load_iris (engine , iris_path , "postgresql" )
418- if not check_target .has_table ("types" ):
417+ if not insp .has_table ("types" ):
419418 create_and_load_types (engine , types_data , "postgresql" )
420419 yield engine
421420 with engine .connect () as conn :
@@ -1450,8 +1449,7 @@ def test_query_by_select_obj(self):
14501449 )
14511450
14521451 iris = iris_table_metadata (self .flavor )
1453- iris_select = iris if _gt14 () else [iris ]
1454- name_select = select (iris_select ).where (iris .c .Name == bindparam ("name" ))
1452+ name_select = select (iris ).where (iris .c .Name == bindparam ("name" ))
14551453 iris_df = sql .read_sql (name_select , self .conn , params = {"name" : "Iris-setosa" })
14561454 all_names = set (iris_df ["Name" ])
14571455 assert all_names == {"Iris-setosa" }
@@ -1624,46 +1622,33 @@ def test_to_sql_empty(self, test_frame1):
16241622 self ._to_sql_empty (test_frame1 )
16251623
16261624 def test_create_table (self ):
1625+ from sqlalchemy import inspect
1626+
16271627 temp_conn = self .connect ()
16281628 temp_frame = DataFrame (
16291629 {"one" : [1.0 , 2.0 , 3.0 , 4.0 ], "two" : [4.0 , 3.0 , 2.0 , 1.0 ]}
16301630 )
1631-
16321631 pandasSQL = sql .SQLDatabase (temp_conn )
16331632 assert pandasSQL .to_sql (temp_frame , "temp_frame" ) == 4
16341633
1635- if _gt14 ():
1636- from sqlalchemy import inspect
1637-
1638- insp = inspect (temp_conn )
1639- assert insp .has_table ("temp_frame" )
1640- else :
1641- assert temp_conn .has_table ("temp_frame" )
1634+ insp = inspect (temp_conn )
1635+ assert insp .has_table ("temp_frame" )
16421636
16431637 def test_drop_table (self ):
1644- temp_conn = self . connect ()
1638+ from sqlalchemy import inspect
16451639
1640+ temp_conn = self .connect ()
16461641 temp_frame = DataFrame (
16471642 {"one" : [1.0 , 2.0 , 3.0 , 4.0 ], "two" : [4.0 , 3.0 , 2.0 , 1.0 ]}
16481643 )
1649-
16501644 pandasSQL = sql .SQLDatabase (temp_conn )
16511645 assert pandasSQL .to_sql (temp_frame , "temp_frame" ) == 4
16521646
1653- if _gt14 ():
1654- from sqlalchemy import inspect
1655-
1656- insp = inspect (temp_conn )
1657- assert insp .has_table ("temp_frame" )
1658- else :
1659- assert temp_conn .has_table ("temp_frame" )
1647+ insp = inspect (temp_conn )
1648+ assert insp .has_table ("temp_frame" )
16601649
16611650 pandasSQL .drop_table ("temp_frame" )
1662-
1663- if _gt14 ():
1664- assert not insp .has_table ("temp_frame" )
1665- else :
1666- assert not temp_conn .has_table ("temp_frame" )
1651+ assert not insp .has_table ("temp_frame" )
16671652
16681653 def test_roundtrip (self , test_frame1 ):
16691654 self ._roundtrip (test_frame1 )
@@ -2156,14 +2141,10 @@ def bar(connection, data):
21562141 data .to_sql (name = "test_foo_data" , con = connection , if_exists = "append" )
21572142
21582143 def baz (conn ):
2159- if _gt14 ():
2160- # https://github.com/sqlalchemy/sqlalchemy/commit/
2161- # 00b5c10846e800304caa86549ab9da373b42fa5d#r48323973
2162- foo_data = foo (conn )
2163- bar (conn , foo_data )
2164- else :
2165- foo_data = conn .run_callable (foo )
2166- conn .run_callable (bar , foo_data )
2144+ # https://github.com/sqlalchemy/sqlalchemy/commit/
2145+ # 00b5c10846e800304caa86549ab9da373b42fa5d#r48323973
2146+ foo_data = foo (conn )
2147+ bar (conn , foo_data )
21672148
21682149 def main (connectable ):
21692150 if isinstance (connectable , Engine ):
@@ -2216,14 +2197,9 @@ def test_temporary_table(self):
22162197 )
22172198 from sqlalchemy .orm import (
22182199 Session ,
2219- sessionmaker ,
2200+ declarative_base ,
22202201 )
22212202
2222- if _gt14 ():
2223- from sqlalchemy .orm import declarative_base
2224- else :
2225- from sqlalchemy .ext .declarative import declarative_base
2226-
22272203 test_data = "Hello, World!"
22282204 expected = DataFrame ({"spam" : [test_data ]})
22292205 Base = declarative_base ()
@@ -2234,24 +2210,13 @@ class Temporary(Base):
22342210 id = Column (Integer , primary_key = True )
22352211 spam = Column (Unicode (30 ), nullable = False )
22362212
2237- if _gt14 ():
2238- with Session (self .conn ) as session :
2239- with session .begin ():
2240- conn = session .connection ()
2241- Temporary .__table__ .create (conn )
2242- session .add (Temporary (spam = test_data ))
2243- session .flush ()
2244- df = sql .read_sql_query (sql = select (Temporary .spam ), con = conn )
2245- else :
2246- Session = sessionmaker ()
2247- session = Session (bind = self .conn )
2248- with session .transaction :
2213+ with Session (self .conn ) as session :
2214+ with session .begin ():
22492215 conn = session .connection ()
22502216 Temporary .__table__ .create (conn )
22512217 session .add (Temporary (spam = test_data ))
22522218 session .flush ()
2253- df = sql .read_sql_query (sql = select ([Temporary .spam ]), con = conn )
2254-
2219+ df = sql .read_sql_query (sql = select (Temporary .spam ), con = conn )
22552220 tm .assert_frame_equal (df , expected )
22562221
22572222 # -- SQL Engine tests (in the base class for now)
@@ -2349,12 +2314,10 @@ def test_row_object_is_named_tuple(self):
23492314 Integer ,
23502315 String ,
23512316 )
2352- from sqlalchemy .orm import sessionmaker
2353-
2354- if _gt14 ():
2355- from sqlalchemy .orm import declarative_base
2356- else :
2357- from sqlalchemy .ext .declarative import declarative_base
2317+ from sqlalchemy .orm import (
2318+ declarative_base ,
2319+ sessionmaker ,
2320+ )
23582321
23592322 BaseModel = declarative_base ()
23602323
0 commit comments