Skip to content

PERF: avoid SQL MetaData reflection in init #45260 #45371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,6 @@ def __init__(self, engine, schema: str | None = None):

self.connectable = engine
self.meta = MetaData(schema=schema)
self.meta.reflect(bind=engine)

@contextmanager
def run_transaction(self):
Expand Down Expand Up @@ -1761,19 +1760,18 @@ def has_table(self, name: str, schema: str | None = None):
)

def get_table(self, table_name: str, schema: str | None = None):
schema = schema or self.meta.schema
if schema:
tbl = self.meta.tables.get(".".join([schema, table_name]))
else:
tbl = self.meta.tables.get(table_name)

# Avoid casting double-precision floats into decimals
from sqlalchemy import Numeric
from sqlalchemy import (
Numeric,
Table,
)

schema = schema or self.meta.schema
tbl = Table(
table_name, self.meta, autoload_with=self.connectable, schema=schema
)
for column in tbl.columns:
if isinstance(column.type, Numeric):
column.type.asdecimal = False

return tbl

def drop_table(self, table_name: str, schema: str | None = None):
Expand Down