Skip to content

Commit 7aad61f

Browse files
TST: Deprecation -> FutureWarning + catch in tests
1 parent 0a00c47 commit 7aad61f

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

pandas/io/sql.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def tquery(sql, con, cur=None, params=None, flavor='sqlite'):
130130
"""
131131
warnings.warn(
132132
"tquery is depreciated, and will be removed in future versions",
133-
DeprecationWarning)
133+
FutureWarning)
134134

135135
pandas_sql = pandasSQL_builder(con, flavor=flavor)
136136
args = _convert_params(sql, params)
@@ -163,7 +163,7 @@ def uquery(sql, con, cur=None, params=None, engine=None, flavor='sqlite'):
163163
"""
164164
warnings.warn(
165165
"uquery is depreciated, and will be removed in future versions",
166-
DeprecationWarning)
166+
FutureWarning)
167167
pandas_sql = pandasSQL_builder(con, flavor=flavor)
168168
args = _convert_params(sql, params)
169169
return pandas_sql.uquery(*args)
@@ -212,7 +212,7 @@ def read_sql_table(table_name, con, meta=None, index_col=None,
212212
--------
213213
read_sql_query : Read SQL query into a DataFrame.
214214
read_sql
215-
215+
216216
217217
"""
218218
pandas_sql = PandasSQLAlchemy(con, meta=meta)
@@ -322,8 +322,8 @@ def read_sql(sql, con, index_col=None, flavor='sqlite', coerce_float=True,
322322
Notes
323323
-----
324324
This function is a convenience wrapper around ``read_sql_table`` and
325-
``read_sql_query`` (and for backward compatibility) and will delegate
326-
to the specific function depending on the provided input (database
325+
``read_sql_query`` (and for backward compatibility) and will delegate
326+
to the specific function depending on the provided input (database
327327
table name or sql query).
328328
329329
See also
@@ -423,13 +423,12 @@ def pandasSQL_builder(con, flavor=None, meta=None):
423423
if isinstance(con, sqlalchemy.engine.Engine):
424424
return PandasSQLAlchemy(con, meta=meta)
425425
else:
426-
warnings.warn(
427-
"""Not an SQLAlchemy engine,
428-
attempting to use as legacy DBAPI connection""")
426+
warnings.warn("Not an SQLAlchemy engine, "
427+
"attempting to use as legacy DBAPI connection")
429428
if flavor is None:
430429
raise ValueError(
431-
"""PandasSQL must be created with an SQLAlchemy engine
432-
or a DBAPI2 connection and SQL flavour""")
430+
"PandasSQL must be created with an SQLAlchemy engine "
431+
"or a DBAPI2 connection and SQL flavor")
433432
else:
434433
return PandasSQLLegacy(con, flavor)
435434

@@ -1006,7 +1005,7 @@ def to_sql(self, frame, name, if_exists='fail', index=True,
10061005
fail: If table exists, do nothing.
10071006
replace: If table exists, drop it, recreate it, and insert data.
10081007
append: If table exists, insert data. Create if does not exist.
1009-
1008+
10101009
"""
10111010
table = PandasSQLTableLegacy(
10121011
name, self, frame=frame, index=index, if_exists=if_exists,
@@ -1041,20 +1040,20 @@ def get_schema(frame, name, con, flavor='sqlite'):
10411040
name: name of SQL table
10421041
con: an open SQL database connection object
10431042
engine: an SQLAlchemy engine - replaces connection and flavor
1044-
flavor: {'sqlite', 'mysql', 'postgres'}, default 'sqlite'
1043+
flavor: {'sqlite', 'mysql'}, default 'sqlite'
10451044
10461045
"""
1047-
warnings.warn(
1048-
"get_schema is depreciated", DeprecationWarning)
1046+
warnings.warn("get_schema is depreciated", FutureWarning)
1047+
10491048
pandas_sql = pandasSQL_builder(con=con, flavor=flavor)
10501049
return pandas_sql._create_sql_schema(frame, name)
10511050

10521051

1052+
10531053
def read_frame(*args, **kwargs):
10541054
"""DEPRECIATED - use read_sql
10551055
"""
1056-
warnings.warn(
1057-
"read_frame is depreciated, use read_sql", DeprecationWarning)
1056+
warnings.warn("read_frame is depreciated, use read_sql", FutureWarning)
10581057
return read_sql(*args, **kwargs)
10591058

10601059

@@ -1092,7 +1091,7 @@ def write_frame(frame, name, con, flavor='sqlite', if_exists='fail', **kwargs):
10921091
pandas.DataFrame.to_sql
10931092
10941093
"""
1095-
warnings.warn("write_frame is depreciated, use to_sql", DeprecationWarning)
1094+
warnings.warn("write_frame is depreciated, use to_sql", FutureWarning)
10961095

10971096
# for backwards compatibility, set index=False when not specified
10981097
index = kwargs.pop('index', False)

pandas/io/tests/test_sql.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,9 @@ def test_read_sql_iris(self):
336336
self._check_iris_loaded_frame(iris_frame)
337337

338338
def test_legacy_read_frame(self):
339-
iris_frame = sql.read_frame(
340-
"SELECT * FROM iris", self.conn, flavor='sqlite')
339+
with tm.assert_produces_warning(FutureWarning):
340+
iris_frame = sql.read_frame(
341+
"SELECT * FROM iris", self.conn, flavor='sqlite')
341342
self._check_iris_loaded_frame(iris_frame)
342343

343344
def test_to_sql(self):
@@ -402,8 +403,10 @@ def test_to_sql_panel(self):
402403
def test_legacy_write_frame(self):
403404
# Assume that functionality is already tested above so just do
404405
# quick check that it basically works
405-
sql.write_frame(self.test_frame1, 'test_frame_legacy', self.conn,
406-
flavor='sqlite')
406+
with tm.assert_produces_warning(FutureWarning):
407+
sql.write_frame(self.test_frame1, 'test_frame_legacy', self.conn,
408+
flavor='sqlite')
409+
407410
self.assertTrue(
408411
sql.has_table('test_frame_legacy', self.conn, flavor='sqlite'),
409412
'Table not written to DB')
@@ -431,11 +434,18 @@ def test_execute_sql(self):
431434
tm.equalContents(row, [5.1, 3.5, 1.4, 0.2, 'Iris-setosa'])
432435

433436
def test_tquery(self):
434-
iris_results = sql.tquery(
435-
"SELECT * FROM iris", con=self.conn, flavor='sqlite')
437+
with tm.assert_produces_warning(FutureWarning):
438+
iris_results = sql.tquery(
439+
"SELECT * FROM iris", con=self.conn, flavor='sqlite')
436440
row = iris_results[0]
437441
tm.equalContents(row, [5.1, 3.5, 1.4, 0.2, 'Iris-setosa'])
438442

443+
def test_uquery(self):
444+
with tm.assert_produces_warning(FutureWarning):
445+
rows = sql.uquery(
446+
"SELECT * FROM iris LIMIT 1", con=self.conn, flavor='sqlite')
447+
self.assertEqual(rows, -1)
448+
439449
def test_date_parsing(self):
440450
# Test date parsing in read_sq
441451
# No Parsing

0 commit comments

Comments
 (0)