From abbaf4be822b5c0608dc9f37b8af2170c6de128e Mon Sep 17 00:00:00 2001 From: Roger Thomas Date: Tue, 12 Apr 2016 14:39:20 +0100 Subject: [PATCH 1/2] Only do case sensitive check when not lower case --- doc/source/whatsnew/v0.18.1.txt | 1 + pandas/io/sql.py | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/doc/source/whatsnew/v0.18.1.txt b/doc/source/whatsnew/v0.18.1.txt index 071cf5f17fc56..2fe2f337763b7 100644 --- a/doc/source/whatsnew/v0.18.1.txt +++ b/doc/source/whatsnew/v0.18.1.txt @@ -203,6 +203,7 @@ Performance Improvements +- Improved performance of ``DataFrame.to_sql`` when checking case sensitivity. Now only checks if table has been created correctly when table name is not lower case. (:issue:`12876`) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 6e309e4210962..324988360c9fe 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -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): From fda61d4a1acdd50ce9cf451673f2f47d7acc8d48 Mon Sep 17 00:00:00 2001 From: Roger Thomas Date: Tue, 12 Apr 2016 15:35:54 +0100 Subject: [PATCH 2/2] Update docs --- doc/source/whatsnew/v0.18.1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.18.1.txt b/doc/source/whatsnew/v0.18.1.txt index 2fe2f337763b7..9785974893e6a 100644 --- a/doc/source/whatsnew/v0.18.1.txt +++ b/doc/source/whatsnew/v0.18.1.txt @@ -203,7 +203,7 @@ Performance Improvements -- Improved performance of ``DataFrame.to_sql`` when checking case sensitivity. Now only checks if table has been created correctly when table name is not lower case. (:issue:`12876`) +- 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`)