Skip to content

Commit a1b3880

Browse files
authored
Backport PR #48736 on branch 1.5.x ( BUG: AttributeError: 'function' object has no attribute 'currentframe') (#48887)
1 parent c7e36af commit a1b3880

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

pandas/io/sql.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1634,8 +1634,8 @@ def prep_table(
16341634

16351635
def check_case_sensitive(
16361636
self,
1637-
name,
1638-
schema,
1637+
name: str,
1638+
schema: str | None,
16391639
) -> None:
16401640
"""
16411641
Checks table name for issues with case-sensitivity.
@@ -1644,10 +1644,10 @@ def check_case_sensitive(
16441644
if not name.isdigit() and not name.islower():
16451645
# check for potentially case sensitivity issues (GH7815)
16461646
# Only check when name is not a number and name is not lower case
1647-
from sqlalchemy import inspect
1647+
from sqlalchemy import inspect as sqlalchemy_inspect
16481648

16491649
with self.connectable.connect() as conn:
1650-
insp = inspect(conn)
1650+
insp = sqlalchemy_inspect(conn)
16511651
table_names = insp.get_table_names(schema=schema or self.meta.schema)
16521652
if name not in table_names:
16531653
msg = (
@@ -1665,11 +1665,11 @@ def check_case_sensitive(
16651665
def to_sql(
16661666
self,
16671667
frame,
1668-
name,
1668+
name: str,
16691669
if_exists: str = "fail",
16701670
index: bool = True,
16711671
index_label=None,
1672-
schema=None,
1672+
schema: str | None = None,
16731673
chunksize=None,
16741674
dtype: DtypeArg | None = None,
16751675
method=None,
@@ -1756,9 +1756,9 @@ def tables(self):
17561756
return self.meta.tables
17571757

17581758
def has_table(self, name: str, schema: str | None = None):
1759-
from sqlalchemy import inspect
1759+
from sqlalchemy import inspect as sqlalchemy_inspect
17601760

1761-
insp = inspect(self.connectable)
1761+
insp = sqlalchemy_inspect(self.connectable)
17621762
return insp.has_table(name, schema or self.meta.schema)
17631763

17641764
def get_table(self, table_name: str, schema: str | None = None) -> Table:

pandas/tests/io/test_sql.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -1357,10 +1357,17 @@ def test_not_reflect_all_tables(self):
13571357

13581358
def test_warning_case_insensitive_table_name(self, test_frame1):
13591359
# see gh-7815
1360-
#
1361-
# We can't test that this warning is triggered, a the database
1362-
# configuration would have to be altered. But here we test that
1363-
# the warning is certainly NOT triggered in a normal case.
1360+
with tm.assert_produces_warning(
1361+
UserWarning,
1362+
match=(
1363+
r"The provided table name 'TABLE1' is not found exactly as such in "
1364+
r"the database after writing the table, possibly due to case "
1365+
r"sensitivity issues. Consider using lower case table names."
1366+
),
1367+
):
1368+
sql.SQLDatabase(self.conn).check_case_sensitive("TABLE1", "")
1369+
1370+
# Test that the warning is certainly NOT triggered in a normal case.
13641371
with tm.assert_produces_warning(None):
13651372
test_frame1.to_sql("CaseSensitive", self.conn)
13661373

0 commit comments

Comments
 (0)