From 4ccc4c61befacad6fa93bb99d4dd74cad2381d76 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Wed, 10 Jan 2018 12:58:37 +0000 Subject: [PATCH] DEPR: Removing previously deprecated flavor parameter from SQLiteDatabase (#6581) (#19121) --- doc/source/whatsnew/v0.23.0.txt | 1 + pandas/core/generic.py | 14 ++++----- pandas/io/sql.py | 52 ++++++--------------------------- pandas/tests/io/test_sql.py | 25 ---------------- 4 files changed, 15 insertions(+), 77 deletions(-) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index b317741b8bec49..84d8caa7f5aaec 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -314,6 +314,7 @@ Removal of prior version deprecations/changes - The ``Panel4D`` and ``PanelND`` classes have been removed (:issue:`13776`) - The ``Panel``class has dropped the ``to_long``and ``toLong`` methods (:issue:`19077`) - The options ``display.line_with`` and ``display.height`` are removed in favor of ``display.width`` and ``display.max_rows`` respectively (:issue:`4391`, :issue:`19107`) +- The ``flavor`` parameter have been removed from func:`to_sql` method (:issue:`13611`) .. _whatsnew_0230.performance: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c9672a43a95a83..cef1e551f948e8 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1842,8 +1842,8 @@ def to_msgpack(self, path_or_buf=None, encoding='utf-8', **kwargs): return packers.to_msgpack(path_or_buf, self, encoding=encoding, **kwargs) - def to_sql(self, name, con, flavor=None, schema=None, if_exists='fail', - index=True, index_label=None, chunksize=None, dtype=None): + def to_sql(self, name, con, schema=None, if_exists='fail', index=True, + index_label=None, chunksize=None, dtype=None): """ Write records stored in a DataFrame to a SQL database. @@ -1854,10 +1854,6 @@ def to_sql(self, name, con, flavor=None, schema=None, if_exists='fail', con : SQLAlchemy engine or DBAPI2 connection (legacy mode) Using SQLAlchemy makes it possible to use any DB supported by that library. If a DBAPI2 object, only sqlite3 is supported. - flavor : 'sqlite', default None - .. deprecated:: 0.19.0 - 'sqlite' is the only supported option if SQLAlchemy is not - used. schema : string, default None Specify the schema (if database flavor supports this). If None, use default schema. @@ -1880,9 +1876,9 @@ def to_sql(self, name, con, flavor=None, schema=None, if_exists='fail', """ from pandas.io import sql - sql.to_sql(self, name, con, flavor=flavor, schema=schema, - if_exists=if_exists, index=index, index_label=index_label, - chunksize=chunksize, dtype=dtype) + sql.to_sql(self, name, con, schema=schema, if_exists=if_exists, + index=index, index_label=index_label, chunksize=chunksize, + dtype=dtype) def to_pickle(self, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL): diff --git a/pandas/io/sql.py b/pandas/io/sql.py index e2f3033c580a52..437e279e909790 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -41,24 +41,6 @@ class DatabaseError(IOError): _SQLALCHEMY_INSTALLED = None -def _validate_flavor_parameter(flavor): - """ - Checks whether a database 'flavor' was specified. - If not None, produces FutureWarning if 'sqlite' and - raises a ValueError if anything else. - """ - if flavor is not None: - if flavor == 'sqlite': - warnings.warn("the 'flavor' parameter is deprecated " - "and will be removed in a future version, " - "as 'sqlite' is the only supported option " - "when SQLAlchemy is not installed.", - FutureWarning, stacklevel=2) - else: - raise ValueError("database flavor {flavor} is not " - "supported".format(flavor=flavor)) - - def _is_sqlalchemy_connectable(con): global _SQLALCHEMY_INSTALLED if _SQLALCHEMY_INSTALLED is None: @@ -415,8 +397,8 @@ def read_sql(sql, con, index_col=None, coerce_float=True, params=None, chunksize=chunksize) -def to_sql(frame, name, con, flavor=None, schema=None, if_exists='fail', - index=True, index_label=None, chunksize=None, dtype=None): +def to_sql(frame, name, con, schema=None, if_exists='fail', index=True, + index_label=None, chunksize=None, dtype=None): """ Write records stored in a DataFrame to a SQL database. @@ -430,10 +412,6 @@ def to_sql(frame, name, con, flavor=None, schema=None, if_exists='fail', Using SQLAlchemy makes it possible to use any DB supported by that library. If a DBAPI2 object, only sqlite3 is supported. - flavor : 'sqlite', default None - .. deprecated:: 0.19.0 - 'sqlite' is the only supported option if SQLAlchemy is not - used. schema : string, default None Name of SQL schema in database to write to (if database flavor supports this). If None, use default schema (default). @@ -459,7 +437,7 @@ def to_sql(frame, name, con, flavor=None, schema=None, if_exists='fail', if if_exists not in ('fail', 'replace', 'append'): raise ValueError("'{0}' is not valid for if_exists".format(if_exists)) - pandas_sql = pandasSQL_builder(con, schema=schema, flavor=flavor) + pandas_sql = pandasSQL_builder(con, schema=schema) if isinstance(frame, Series): frame = frame.to_frame() @@ -472,7 +450,7 @@ def to_sql(frame, name, con, flavor=None, schema=None, if_exists='fail', chunksize=chunksize, dtype=dtype) -def has_table(table_name, con, flavor=None, schema=None): +def has_table(table_name, con, schema=None): """ Check if DataBase has named table. @@ -484,10 +462,6 @@ def has_table(table_name, con, flavor=None, schema=None): Using SQLAlchemy makes it possible to use any DB supported by that library. If a DBAPI2 object, only sqlite3 is supported. - flavor : 'sqlite', default None - .. deprecated:: 0.19.0 - 'sqlite' is the only supported option if SQLAlchemy is not - installed. schema : string, default None Name of SQL schema in database to write to (if database flavor supports this). If None, use default schema (default). @@ -496,7 +470,7 @@ def has_table(table_name, con, flavor=None, schema=None): ------- boolean """ - pandas_sql = pandasSQL_builder(con, flavor=flavor, schema=schema) + pandas_sql = pandasSQL_builder(con, schema=schema) return pandas_sql.has_table(table_name) @@ -521,14 +495,12 @@ def _engine_builder(con): return con -def pandasSQL_builder(con, flavor=None, schema=None, meta=None, +def pandasSQL_builder(con, schema=None, meta=None, is_cursor=False): """ Convenience function to return the correct PandasSQL subclass based on the provided parameters. """ - _validate_flavor_parameter(flavor) - # When support for DBAPI connections is removed, # is_cursor should not be necessary. con = _engine_builder(con) @@ -1378,9 +1350,7 @@ class SQLiteDatabase(PandasSQL): """ - def __init__(self, con, flavor=None, is_cursor=False): - _validate_flavor_parameter(flavor) - + def __init__(self, con, is_cursor=False): self.is_cursor = is_cursor self.con = con @@ -1534,7 +1504,7 @@ def _create_sql_schema(self, frame, table_name, keys=None, dtype=None): return str(table.sql_schema()) -def get_schema(frame, name, flavor=None, keys=None, con=None, dtype=None): +def get_schema(frame, name, keys=None, con=None, dtype=None): """ Get the SQL db table schema for the given frame. @@ -1549,15 +1519,11 @@ def get_schema(frame, name, flavor=None, keys=None, con=None, dtype=None): Using SQLAlchemy makes it possible to use any DB supported by that library, default: None If a DBAPI2 object, only sqlite3 is supported. - flavor : 'sqlite', default None - .. deprecated:: 0.19.0 - 'sqlite' is the only supported option if SQLAlchemy is not - installed. dtype : dict of column name to SQL type, default None Optional specifying the datatype for columns. The SQL type should be a SQLAlchemy type, or a string for sqlite3 fallback connection. """ - pandas_sql = pandasSQL_builder(con=con, flavor=flavor) + pandas_sql = pandasSQL_builder(con=con) return pandas_sql._create_sql_schema(frame, name, keys=keys, dtype=dtype) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 217fc8e67483d6..0cc4101cd63040 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -2333,31 +2333,6 @@ def clean_up(test_table_to_drop): clean_up(table_name) -@pytest.mark.single -class TestSQLFlavorDeprecation(object): - """ - gh-13611: test that the 'flavor' parameter - is appropriately deprecated by checking the - functions that directly raise the warning - """ - - con = 1234 # don't need real connection for this - funcs = ['SQLiteDatabase', 'pandasSQL_builder'] - - def test_unsupported_flavor(self): - msg = 'is not supported' - - for func in self.funcs: - tm.assert_raises_regex(ValueError, msg, getattr(sql, func), - self.con, flavor='mysql') - - def test_deprecated_flavor(self): - for func in self.funcs: - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - getattr(sql, func)(self.con, flavor='sqlite') - - @pytest.mark.single @pytest.mark.skip(reason="gh-13611: there is no support for MySQL " "if SQLAlchemy is not installed")