Skip to content

Commit

Permalink
chore: remove _fetch_from_cursor double close call
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Sep 9, 2024
1 parent 0f09678 commit 837e3d2
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions ibis/backends/mysql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def from_connection(cls, con: pymysql.Connection) -> Backend:
return new_backend

def _post_connect(self) -> None:
with contextlib.closing(self.con.cursor()) as cur:
with self.con.cursor() as cur:
try:
cur.execute("SET @@session.time_zone = 'UTC'")
except Exception as e: # noqa: BLE001
Expand Down Expand Up @@ -269,7 +269,7 @@ def begin(self):
# from .execute()
@contextlib.contextmanager
def _safe_raw_sql(self, *args, **kwargs):
with contextlib.closing(self.raw_sql(*args, **kwargs)) as result:
with self.raw_sql(*args, **kwargs) as result:
yield result

def raw_sql(self, query: str | sg.Expression, **kwargs: Any) -> Any:
Expand Down Expand Up @@ -522,16 +522,6 @@ def _fetch_from_cursor(self, cursor, schema: sch.Schema) -> pd.DataFrame:

from ibis.backends.mysql.converter import MySQLPandasData

try:
df = pd.DataFrame.from_records(
cursor, columns=schema.names, coerce_float=True
)
except Exception:
# clean up the cursor if we fail to create the DataFrame
#
# in the sqlite case failing to close the cursor results in
# artificially locked tables
cursor.close()
raise
df = pd.DataFrame.from_records(cursor, columns=schema.names, coerce_float=True)
df = MySQLPandasData.convert_table(df, schema)
return df

0 comments on commit 837e3d2

Please sign in to comment.