Skip to content

Commit 4318403

Browse files
fangchenlifeefladder
authored andcommitted
CLN: remove deprecated sqlite cursor (pandas-dev#42507)
1 parent 5a90aa2 commit 4318403

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

pandas/io/sql.py

+6-18
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def _wrap_result(
182182
return frame
183183

184184

185-
def execute(sql, con, cur=None, params=None):
185+
def execute(sql, con, params=None):
186186
"""
187187
Execute the given SQL query using the provided connection object.
188188
@@ -194,18 +194,14 @@ def execute(sql, con, cur=None, params=None):
194194
Using SQLAlchemy makes it possible to use any DB supported by the
195195
library.
196196
If a DBAPI2 object, only sqlite3 is supported.
197-
cur : deprecated, cursor is obtained from connection, default: None
198197
params : list or tuple, optional, default: None
199198
List of parameters to pass to execute method.
200199
201200
Returns
202201
-------
203202
Results Iterable
204203
"""
205-
if cur is None:
206-
pandas_sql = pandasSQL_builder(con)
207-
else:
208-
pandas_sql = pandasSQL_builder(cur, is_cursor=True)
204+
pandas_sql = pandasSQL_builder(con)
209205
args = _convert_params(sql, params)
210206
return pandas_sql.execute(*args)
211207

@@ -774,22 +770,18 @@ def _engine_builder(con):
774770
return con
775771

776772

777-
def pandasSQL_builder(
778-
con, schema: str | None = None, meta=None, is_cursor: bool = False
779-
):
773+
def pandasSQL_builder(con, schema: str | None = None, meta=None):
780774
"""
781775
Convenience function to return the correct PandasSQL subclass based on the
782776
provided parameters.
783777
"""
784-
# When support for DBAPI connections is removed,
785-
# is_cursor should not be necessary.
786778
con = _engine_builder(con)
787779
if _is_sqlalchemy_connectable(con):
788780
return SQLDatabase(con, schema=schema, meta=meta)
789781
elif isinstance(con, str):
790782
raise ImportError("Using URI string without sqlalchemy installed.")
791783
else:
792-
return SQLiteDatabase(con, is_cursor=is_cursor)
784+
return SQLiteDatabase(con)
793785

794786

795787
class SQLTable(PandasObject):
@@ -2031,8 +2023,7 @@ class SQLiteDatabase(PandasSQL):
20312023
20322024
"""
20332025

2034-
def __init__(self, con, is_cursor: bool = False):
2035-
self.is_cursor = is_cursor
2026+
def __init__(self, con):
20362027
self.con = con
20372028

20382029
@contextmanager
@@ -2048,10 +2039,7 @@ def run_transaction(self):
20482039
cur.close()
20492040

20502041
def execute(self, *args, **kwargs):
2051-
if self.is_cursor:
2052-
cur = self.con
2053-
else:
2054-
cur = self.con.cursor()
2042+
cur = self.con.cursor()
20552043
try:
20562044
cur.execute(*args, **kwargs)
20572045
return cur

pandas/tests/io/test_sql.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -2615,9 +2615,9 @@ def format_query(sql, *args):
26152615
return sql % tuple(processed_args)
26162616

26172617

2618-
def tquery(query, con=None, cur=None):
2618+
def tquery(query, con=None):
26192619
"""Replace removed sql.tquery function"""
2620-
res = sql.execute(query, con=con, cur=cur).fetchall()
2620+
res = sql.execute(query, con=con).fetchall()
26212621
if res is None:
26222622
return None
26232623
else:
@@ -2649,12 +2649,10 @@ def test_write_row_by_row(self):
26492649
cur = self.conn.cursor()
26502650
cur.execute(create_sql)
26512651

2652-
cur = self.conn.cursor()
2653-
26542652
ins = "INSERT INTO test VALUES (%s, %s, %s, %s)"
2655-
for idx, row in frame.iterrows():
2653+
for _, row in frame.iterrows():
26562654
fmt_sql = format_query(ins, *row)
2657-
tquery(fmt_sql, cur=cur)
2655+
tquery(fmt_sql, con=self.conn)
26582656

26592657
self.conn.commit()
26602658

@@ -2912,9 +2910,9 @@ def test_write_row_by_row(self):
29122910
cur.execute(drop_sql)
29132911
cur.execute(create_sql)
29142912
ins = "INSERT INTO test VALUES (%s, %s, %s, %s)"
2915-
for idx, row in frame.iterrows():
2913+
for _, row in frame.iterrows():
29162914
fmt_sql = format_query(ins, *row)
2917-
tquery(fmt_sql, cur=cur)
2915+
tquery(fmt_sql, con=self.conn)
29182916

29192917
self.conn.commit()
29202918

0 commit comments

Comments
 (0)