Skip to content

Commit 4ccc4c6

Browse files
datapythonistamaxim veksler
authored and
maxim veksler
committed
DEPR: Removing previously deprecated flavor parameter from SQLiteDatabase (pandas-dev#6581) (pandas-dev#19121)
1 parent d40074f commit 4ccc4c6

File tree

4 files changed

+15
-77
lines changed

4 files changed

+15
-77
lines changed

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ Removal of prior version deprecations/changes
314314
- The ``Panel4D`` and ``PanelND`` classes have been removed (:issue:`13776`)
315315
- The ``Panel``class has dropped the ``to_long``and ``toLong`` methods (:issue:`19077`)
316316
- The options ``display.line_with`` and ``display.height`` are removed in favor of ``display.width`` and ``display.max_rows`` respectively (:issue:`4391`, :issue:`19107`)
317+
- The ``flavor`` parameter have been removed from func:`to_sql` method (:issue:`13611`)
317318

318319
.. _whatsnew_0230.performance:
319320

pandas/core/generic.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -1842,8 +1842,8 @@ def to_msgpack(self, path_or_buf=None, encoding='utf-8', **kwargs):
18421842
return packers.to_msgpack(path_or_buf, self, encoding=encoding,
18431843
**kwargs)
18441844

1845-
def to_sql(self, name, con, flavor=None, schema=None, if_exists='fail',
1846-
index=True, index_label=None, chunksize=None, dtype=None):
1845+
def to_sql(self, name, con, schema=None, if_exists='fail', index=True,
1846+
index_label=None, chunksize=None, dtype=None):
18471847
"""
18481848
Write records stored in a DataFrame to a SQL database.
18491849
@@ -1854,10 +1854,6 @@ def to_sql(self, name, con, flavor=None, schema=None, if_exists='fail',
18541854
con : SQLAlchemy engine or DBAPI2 connection (legacy mode)
18551855
Using SQLAlchemy makes it possible to use any DB supported by that
18561856
library. If a DBAPI2 object, only sqlite3 is supported.
1857-
flavor : 'sqlite', default None
1858-
.. deprecated:: 0.19.0
1859-
'sqlite' is the only supported option if SQLAlchemy is not
1860-
used.
18611857
schema : string, default None
18621858
Specify the schema (if database flavor supports this). If None, use
18631859
default schema.
@@ -1880,9 +1876,9 @@ def to_sql(self, name, con, flavor=None, schema=None, if_exists='fail',
18801876
18811877
"""
18821878
from pandas.io import sql
1883-
sql.to_sql(self, name, con, flavor=flavor, schema=schema,
1884-
if_exists=if_exists, index=index, index_label=index_label,
1885-
chunksize=chunksize, dtype=dtype)
1879+
sql.to_sql(self, name, con, schema=schema, if_exists=if_exists,
1880+
index=index, index_label=index_label, chunksize=chunksize,
1881+
dtype=dtype)
18861882

18871883
def to_pickle(self, path, compression='infer',
18881884
protocol=pkl.HIGHEST_PROTOCOL):

pandas/io/sql.py

+9-43
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,6 @@ class DatabaseError(IOError):
4141
_SQLALCHEMY_INSTALLED = None
4242

4343

44-
def _validate_flavor_parameter(flavor):
45-
"""
46-
Checks whether a database 'flavor' was specified.
47-
If not None, produces FutureWarning if 'sqlite' and
48-
raises a ValueError if anything else.
49-
"""
50-
if flavor is not None:
51-
if flavor == 'sqlite':
52-
warnings.warn("the 'flavor' parameter is deprecated "
53-
"and will be removed in a future version, "
54-
"as 'sqlite' is the only supported option "
55-
"when SQLAlchemy is not installed.",
56-
FutureWarning, stacklevel=2)
57-
else:
58-
raise ValueError("database flavor {flavor} is not "
59-
"supported".format(flavor=flavor))
60-
61-
6244
def _is_sqlalchemy_connectable(con):
6345
global _SQLALCHEMY_INSTALLED
6446
if _SQLALCHEMY_INSTALLED is None:
@@ -415,8 +397,8 @@ def read_sql(sql, con, index_col=None, coerce_float=True, params=None,
415397
chunksize=chunksize)
416398

417399

418-
def to_sql(frame, name, con, flavor=None, schema=None, if_exists='fail',
419-
index=True, index_label=None, chunksize=None, dtype=None):
400+
def to_sql(frame, name, con, schema=None, if_exists='fail', index=True,
401+
index_label=None, chunksize=None, dtype=None):
420402
"""
421403
Write records stored in a DataFrame to a SQL database.
422404
@@ -430,10 +412,6 @@ def to_sql(frame, name, con, flavor=None, schema=None, if_exists='fail',
430412
Using SQLAlchemy makes it possible to use any DB supported by that
431413
library.
432414
If a DBAPI2 object, only sqlite3 is supported.
433-
flavor : 'sqlite', default None
434-
.. deprecated:: 0.19.0
435-
'sqlite' is the only supported option if SQLAlchemy is not
436-
used.
437415
schema : string, default None
438416
Name of SQL schema in database to write to (if database flavor
439417
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',
459437
if if_exists not in ('fail', 'replace', 'append'):
460438
raise ValueError("'{0}' is not valid for if_exists".format(if_exists))
461439

462-
pandas_sql = pandasSQL_builder(con, schema=schema, flavor=flavor)
440+
pandas_sql = pandasSQL_builder(con, schema=schema)
463441

464442
if isinstance(frame, Series):
465443
frame = frame.to_frame()
@@ -472,7 +450,7 @@ def to_sql(frame, name, con, flavor=None, schema=None, if_exists='fail',
472450
chunksize=chunksize, dtype=dtype)
473451

474452

475-
def has_table(table_name, con, flavor=None, schema=None):
453+
def has_table(table_name, con, schema=None):
476454
"""
477455
Check if DataBase has named table.
478456
@@ -484,10 +462,6 @@ def has_table(table_name, con, flavor=None, schema=None):
484462
Using SQLAlchemy makes it possible to use any DB supported by that
485463
library.
486464
If a DBAPI2 object, only sqlite3 is supported.
487-
flavor : 'sqlite', default None
488-
.. deprecated:: 0.19.0
489-
'sqlite' is the only supported option if SQLAlchemy is not
490-
installed.
491465
schema : string, default None
492466
Name of SQL schema in database to write to (if database flavor supports
493467
this). If None, use default schema (default).
@@ -496,7 +470,7 @@ def has_table(table_name, con, flavor=None, schema=None):
496470
-------
497471
boolean
498472
"""
499-
pandas_sql = pandasSQL_builder(con, flavor=flavor, schema=schema)
473+
pandas_sql = pandasSQL_builder(con, schema=schema)
500474
return pandas_sql.has_table(table_name)
501475

502476

@@ -521,14 +495,12 @@ def _engine_builder(con):
521495
return con
522496

523497

524-
def pandasSQL_builder(con, flavor=None, schema=None, meta=None,
498+
def pandasSQL_builder(con, schema=None, meta=None,
525499
is_cursor=False):
526500
"""
527501
Convenience function to return the correct PandasSQL subclass based on the
528502
provided parameters.
529503
"""
530-
_validate_flavor_parameter(flavor)
531-
532504
# When support for DBAPI connections is removed,
533505
# is_cursor should not be necessary.
534506
con = _engine_builder(con)
@@ -1378,9 +1350,7 @@ class SQLiteDatabase(PandasSQL):
13781350
13791351
"""
13801352

1381-
def __init__(self, con, flavor=None, is_cursor=False):
1382-
_validate_flavor_parameter(flavor)
1383-
1353+
def __init__(self, con, is_cursor=False):
13841354
self.is_cursor = is_cursor
13851355
self.con = con
13861356

@@ -1534,7 +1504,7 @@ def _create_sql_schema(self, frame, table_name, keys=None, dtype=None):
15341504
return str(table.sql_schema())
15351505

15361506

1537-
def get_schema(frame, name, flavor=None, keys=None, con=None, dtype=None):
1507+
def get_schema(frame, name, keys=None, con=None, dtype=None):
15381508
"""
15391509
Get the SQL db table schema for the given frame.
15401510
@@ -1549,15 +1519,11 @@ def get_schema(frame, name, flavor=None, keys=None, con=None, dtype=None):
15491519
Using SQLAlchemy makes it possible to use any DB supported by that
15501520
library, default: None
15511521
If a DBAPI2 object, only sqlite3 is supported.
1552-
flavor : 'sqlite', default None
1553-
.. deprecated:: 0.19.0
1554-
'sqlite' is the only supported option if SQLAlchemy is not
1555-
installed.
15561522
dtype : dict of column name to SQL type, default None
15571523
Optional specifying the datatype for columns. The SQL type should
15581524
be a SQLAlchemy type, or a string for sqlite3 fallback connection.
15591525
15601526
"""
15611527

1562-
pandas_sql = pandasSQL_builder(con=con, flavor=flavor)
1528+
pandas_sql = pandasSQL_builder(con=con)
15631529
return pandas_sql._create_sql_schema(frame, name, keys=keys, dtype=dtype)

pandas/tests/io/test_sql.py

-25
Original file line numberDiff line numberDiff line change
@@ -2333,31 +2333,6 @@ def clean_up(test_table_to_drop):
23332333
clean_up(table_name)
23342334

23352335

2336-
@pytest.mark.single
2337-
class TestSQLFlavorDeprecation(object):
2338-
"""
2339-
gh-13611: test that the 'flavor' parameter
2340-
is appropriately deprecated by checking the
2341-
functions that directly raise the warning
2342-
"""
2343-
2344-
con = 1234 # don't need real connection for this
2345-
funcs = ['SQLiteDatabase', 'pandasSQL_builder']
2346-
2347-
def test_unsupported_flavor(self):
2348-
msg = 'is not supported'
2349-
2350-
for func in self.funcs:
2351-
tm.assert_raises_regex(ValueError, msg, getattr(sql, func),
2352-
self.con, flavor='mysql')
2353-
2354-
def test_deprecated_flavor(self):
2355-
for func in self.funcs:
2356-
with tm.assert_produces_warning(FutureWarning,
2357-
check_stacklevel=False):
2358-
getattr(sql, func)(self.con, flavor='sqlite')
2359-
2360-
23612336
@pytest.mark.single
23622337
@pytest.mark.skip(reason="gh-13611: there is no support for MySQL "
23632338
"if SQLAlchemy is not installed")

0 commit comments

Comments
 (0)