Skip to content

Commit

Permalink
PERF: Only do case sensitive check when not lower case
Browse files Browse the repository at this point in the history
closes #12876

Author: Roger Thomas <roger.thomas@cremeglobal.com>

Closes #12880 from RogerThomas/to_sql_only_check_case_when_not_lower and squashes the following commits:

fda61d4 [Roger Thomas] Update docs
abbaf4b [Roger Thomas] Only do case sensitive check when not lower case
  • Loading branch information
Roger Thomas authored and jreback committed Apr 13, 2016
1 parent 77be872 commit 5a53f03
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.18.1.txt
Expand Up @@ -203,6 +203,7 @@ Performance Improvements



- Improved performance of ``DataFrame.to_sql`` when checking case sensitivity for tables. Now only checks if table has been created correctly when table name is not lower case. (:issue:`12876`)



Expand Down
30 changes: 17 additions & 13 deletions pandas/io/sql.py
Expand Up @@ -1248,19 +1248,23 @@ def to_sql(self, frame, name, if_exists='fail', index=True,
schema=schema, dtype=dtype)
table.create()
table.insert(chunksize)
# check for potentially case sensitivity issues (GH7815)
engine = self.connectable.engine
with self.connectable.connect() as conn:
table_names = engine.table_names(
schema=schema or self.meta.schema,
connection=conn,
)
if name not in table_names:
warnings.warn("The provided table name '{0}' is not found exactly "
"as such in the database after writing the table, "
"possibly due to case sensitivity issues. Consider "
"using lower case table names.".format(name),
UserWarning)
if (not name.isdigit() and not name.islower()):
# check for potentially case sensitivity issues (GH7815)
# Only check when name is not a number and name is not lower case
engine = self.connectable.engine
with self.connectable.connect() as conn:
table_names = engine.table_names(
schema=schema or self.meta.schema,
connection=conn,
)
if name not in table_names:
msg = (
"The provided table name '{0}' is not found exactly as "
"such in the database after writing the table, possibly "
"due to case sensitivity issues. Consider using lower "
"case table names."
).format(name)
warnings.warn(msg, UserWarning)

@property
def tables(self):
Expand Down

0 comments on commit 5a53f03

Please sign in to comment.