From 0c6c0299e1da4273aa47ab1426cc4ffd7e054b5e Mon Sep 17 00:00:00 2001 From: luke <2736230899@qq.com> Date: Mon, 9 Jan 2023 16:29:05 +0800 Subject: [PATCH 1/4] add-FutureWarning-pandas.io.sql.execute --- doc/source/whatsnew/v2.0.0.rst | 2 +- pandas/io/sql.py | 6 ++++++ pandas/tests/io/test_sql.py | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 3ea4447cdfa93..95c760ebaef9a 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -510,7 +510,7 @@ 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: 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..15c45821f959e 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -668,6 +668,15 @@ def test_execute_typeerror(sqlite_iris_engine): sql.execute("select * from iris", sqlite_iris_engine) +def test_execute_deprecated(sqlite_buildin_iris): + 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. From d055ee0027d8a0a762fee68d461e978d07afbbe4 Mon Sep 17 00:00:00 2001 From: luke <2736230899@qq.com> Date: Mon, 9 Jan 2023 23:32:48 +0800 Subject: [PATCH 2/4] add GH and try fix doc build --- doc/source/whatsnew/v2.0.0.rst | 2 +- pandas/tests/io/test_sql.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 95c760ebaef9a..efbdd52aa30b3 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -510,7 +510,7 @@ 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`) +- Deprecated ``pandas.io.sql.execute``(:issue:`50185`) .. --------------------------------------------------------------------------- .. _whatsnew_200.prior_deprecations: diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 15c45821f959e..f83b6b0373a87 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -669,6 +669,7 @@ def test_execute_typeerror(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 " From eca7ca39467f56fba626159ff3aa36421af7e518 Mon Sep 17 00:00:00 2001 From: luke <2736230899@qq.com> Date: Tue, 10 Jan 2023 11:38:16 +0800 Subject: [PATCH 3/4] try fix doc build --- doc/source/whatsnew/v2.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 992b51387eda8..27053a9a5df23 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -553,7 +553,7 @@ 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 ``pandas.io.sql.execute``(:issue:`50185`) +- Deprecated :func:`pandas.io.sql.execute`(:issue:`50185`) .. --------------------------------------------------------------------------- .. _whatsnew_200.prior_deprecations: From 17f3427a698529337c58b54d510f188df7fecc45 Mon Sep 17 00:00:00 2001 From: luke <2736230899@qq.com> Date: Wed, 11 Jan 2023 23:25:05 +0800 Subject: [PATCH 4/4] add blank line --- doc/source/whatsnew/v2.0.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 27053a9a5df23..3c914bb16ecde 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -554,8 +554,9 @@ 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