From c8687839493d3c91250e748fe5309687038e96ac Mon Sep 17 00:00:00 2001 From: Saul Pwanson Date: Tue, 18 Jan 2022 13:39:57 -0800 Subject: [PATCH] refactor(sqlalchemy): remove unnecessary _AutoCloseCursor #2947 --- ibis/backends/base/sql/alchemy/__init__.py | 29 ++-------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/ibis/backends/base/sql/alchemy/__init__.py b/ibis/backends/base/sql/alchemy/__init__.py index e41bd7e1e8e2..c2bd209812dd 100644 --- a/ibis/backends/base/sql/alchemy/__init__.py +++ b/ibis/backends/base/sql/alchemy/__init__.py @@ -52,28 +52,6 @@ ) -class _AutoCloseCursor: - """ - Wraps a SQLAlchemy ResultProxy and ensures that .close() is called on - garbage collection - """ - - def __init__(self, original_cursor): - self.original_cursor = original_cursor - - def __del__(self): - self.original_cursor.close() - - def __enter__(self): - return self - - def __exit__(self, type, value, tb): - self.original_cursor.close() - - def fetchall(self): - return self.original_cursor.fetchall() - - class BaseAlchemyBackend(BaseSQLBackend): """ Base backend class for backends that compile to SQL with SQLAlchemy. @@ -151,8 +129,8 @@ def to_shapely(row, name): def fetch_from_cursor(self, cursor, schema): df = pd.DataFrame.from_records( - cursor.original_cursor.fetchall(), - columns=cursor.original_cursor.keys(), + cursor.fetchall(), + columns=cursor.keys(), coerce_float=True, ) df = schema.apply_to(df) @@ -326,9 +304,6 @@ def current_database(self): def list_schemas(self): return self.list_databases() - def raw_sql(self, query: str, results=False): - return _AutoCloseCursor(super().raw_sql(query)) - def _log(self, sql): try: query_str = str(sql)