Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: Removing previously deprecated flavor parameter from SQLiteData… #19121

Merged
merged 1 commit into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
14 changes: 5 additions & 9 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
Expand All @@ -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):
Expand Down
52 changes: 9 additions & 43 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.

Expand All @@ -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).
Expand All @@ -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()
Expand All @@ -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.

Expand All @@ -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).
Expand All @@ -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)


Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand All @@ -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)
25 changes: 0 additions & 25 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down