Skip to content

Commit 69f46d1

Browse files
MarcoGorellinoatamir
authored andcommitted
BUG: AttributeError: 'function' object has no attribute 'currentframe' (pandas-dev#48736)
* sqlalchemy.inspect shouldnt shadow builtin inspect * 🏷️ * reword in terms of to_sql * import sqlalchemy.inspect as sqlalchemy_inspect Co-authored-by: MarcoGorelli <>
1 parent ffbe7e3 commit 69f46d1

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

doc/source/whatsnew/v1.5.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Fixed regressions
7474
- Regression in :func:`.read_csv` causing an ``EmptyDataError`` when using an UTF-8 file handle that was already read from (:issue:`48646`)
7575
- Fixed regression in :meth:`DataFrame.plot` ignoring invalid ``colormap`` for ``kind="scatter"`` (:issue:`48726`)
7676
- Fixed performance regression in :func:`factorize` when ``na_sentinel`` is not ``None`` and ``sort=False`` (:issue:`48620`)
77-
-
77+
- Fixed regression causing an ``AttributeError`` during warning emitted if the provided table name in :meth:`DataFrame.to_sql` and the table name actually used in the database do not match (:issue:`48733`)
7878

7979
.. ---------------------------------------------------------------------------
8080

pandas/io/sql.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1635,8 +1635,8 @@ def prep_table(
16351635

16361636
def check_case_sensitive(
16371637
self,
1638-
name,
1639-
schema,
1638+
name: str,
1639+
schema: str | None,
16401640
) -> None:
16411641
"""
16421642
Checks table name for issues with case-sensitivity.
@@ -1645,10 +1645,10 @@ def check_case_sensitive(
16451645
if not name.isdigit() and not name.islower():
16461646
# check for potentially case sensitivity issues (GH7815)
16471647
# Only check when name is not a number and name is not lower case
1648-
from sqlalchemy import inspect
1648+
from sqlalchemy import inspect as sqlalchemy_inspect
16491649

16501650
with self.connectable.connect() as conn:
1651-
insp = inspect(conn)
1651+
insp = sqlalchemy_inspect(conn)
16521652
table_names = insp.get_table_names(schema=schema or self.meta.schema)
16531653
if name not in table_names:
16541654
msg = (
@@ -1666,11 +1666,11 @@ def check_case_sensitive(
16661666
def to_sql(
16671667
self,
16681668
frame,
1669-
name,
1669+
name: str,
16701670
if_exists: Literal["fail", "replace", "append"] = "fail",
16711671
index: bool = True,
16721672
index_label=None,
1673-
schema=None,
1673+
schema: str | None = None,
16741674
chunksize=None,
16751675
dtype: DtypeArg | None = None,
16761676
method=None,
@@ -1757,9 +1757,9 @@ def tables(self):
17571757
return self.meta.tables
17581758

17591759
def has_table(self, name: str, schema: str | None = None):
1760-
from sqlalchemy import inspect
1760+
from sqlalchemy import inspect as sqlalchemy_inspect
17611761

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

17651765
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)