diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 9a99dbad30708..39a93304bfe5a 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -556,9 +556,10 @@ Other API changes Deprecations ~~~~~~~~~~~~ - Deprecated argument ``infer_datetime_format`` in :func:`to_datetime` and :func:`read_csv`, as a strict version of it is now the default (:issue:`48621`) +- Deprecated :func:`pandas.io.sql.execute`(:issue:`50185`) +- .. --------------------------------------------------------------------------- - .. _whatsnew_200.prior_deprecations: Removal of prior version deprecations/changes diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 2b845786b0366..eea97fc0d9760 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -201,6 +201,12 @@ def execute(sql, con, params=None): ------- Results Iterable """ + warnings.warn( + "`pandas.io.sql.execute` is deprecated and " + "will be removed in the future version.", + FutureWarning, + stacklevel=find_stack_level(), + ) # GH50185 sqlalchemy = import_optional_dependency("sqlalchemy", errors="ignore") if sqlalchemy is not None and isinstance(con, (str, sqlalchemy.engine.Engine)): diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 31ca060e36ad1..f83b6b0373a87 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -668,6 +668,16 @@ def test_execute_typeerror(sqlite_iris_engine): sql.execute("select * from iris", sqlite_iris_engine) +def test_execute_deprecated(sqlite_buildin_iris): + # GH50185 + with tm.assert_produces_warning( + FutureWarning, + match="`pandas.io.sql.execute` is deprecated and " + "will be removed in the future version.", + ): + sql.execute("select * from iris", sqlite_buildin_iris) + + class MixInBase: def teardown_method(self): # if setup fails, there may not be a connection to close.