Skip to content

Commit a659f1d

Browse files
authored
PERF: avoid SQL MetaData reflection in init #45260 (#45371)
1 parent e3ff3d9 commit a659f1d

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

pandas/io/sql.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,6 @@ def __init__(self, engine, schema: str | None = None):
13781378

13791379
self.connectable = engine
13801380
self.meta = MetaData(schema=schema)
1381-
self.meta.reflect(bind=engine)
13821381

13831382
@contextmanager
13841383
def run_transaction(self):
@@ -1761,19 +1760,18 @@ def has_table(self, name: str, schema: str | None = None):
17611760
)
17621761

17631762
def get_table(self, table_name: str, schema: str | None = None):
1764-
schema = schema or self.meta.schema
1765-
if schema:
1766-
tbl = self.meta.tables.get(".".join([schema, table_name]))
1767-
else:
1768-
tbl = self.meta.tables.get(table_name)
1769-
1770-
# Avoid casting double-precision floats into decimals
1771-
from sqlalchemy import Numeric
1763+
from sqlalchemy import (
1764+
Numeric,
1765+
Table,
1766+
)
17721767

1768+
schema = schema or self.meta.schema
1769+
tbl = Table(
1770+
table_name, self.meta, autoload_with=self.connectable, schema=schema
1771+
)
17731772
for column in tbl.columns:
17741773
if isinstance(column.type, Numeric):
17751774
column.type.asdecimal = False
1776-
17771775
return tbl
17781776

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

0 commit comments

Comments
 (0)