From 6059bf8b025f8ec631ae7e81e9c85cb6bf56deb1 Mon Sep 17 00:00:00 2001 From: tl3119 Date: Mon, 26 Jun 2023 13:19:31 -0400 Subject: [PATCH 1/6] Update run.py --- src/sql/run.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sql/run.py b/src/sql/run.py index fb8bcaff3..29b60a190 100644 --- a/src/sql/run.py +++ b/src/sql/run.py @@ -233,6 +233,7 @@ def pie(self, key_word_sep=" ", title=None, **kwargs): Any additional keyword arguments will be passed through to ``matplotlib.pylab.pie``. """ + warnings.warn("Please use %sqlplot API") self.guess_pie_columns(xlabel_sep=key_word_sep) import matplotlib.pylab as plt @@ -302,6 +303,7 @@ def bar(self, key_word_sep=" ", title=None, **kwargs): Any additional keyword arguments will be passed through to ``matplotlib.pylab.bar``. """ + warnings.warn("Please use %sqlplot API") import matplotlib.pylab as plt ax = plt.gca() From 60d92852596a1877ab0963afb6ff77b54175d9f2 Mon Sep 17 00:00:00 2001 From: tl3119 Date: Mon, 26 Jun 2023 13:23:16 -0400 Subject: [PATCH 2/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70bae7a1f..9f8936a92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * [Fix] Fixed CI issue by updating `invalid_connection_string_duckdb` in `test_magic.py` (#631) * [Fix] Refactored `ResultSet` to lazy loading (#470) +* [Fix] Showed depcrecation warnings message for plot API ([#513](https://github.com/ploomber/jupysql/issues/513)) ## 0.7.9 (2023-06-19) From 57fa5c065d1f486dbba97be426e093b503c6aa29 Mon Sep 17 00:00:00 2001 From: tl3119 Date: Tue, 27 Jun 2023 01:10:43 -0400 Subject: [PATCH 3/6] Update warning message --- src/sql/run.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/sql/run.py b/src/sql/run.py index 29b60a190..593bf3550 100644 --- a/src/sql/run.py +++ b/src/sql/run.py @@ -233,7 +233,13 @@ def pie(self, key_word_sep=" ", title=None, **kwargs): Any additional keyword arguments will be passed through to ``matplotlib.pylab.pie``. """ - warnings.warn("Please use %sqlplot API") + warnings.warn( + ( + ".pie() will be removed in a future version," + "please use %sqlplot bar. If you need help migrating," + "send us a message: https://ploomber.io/community" + ) + ) self.guess_pie_columns(xlabel_sep=key_word_sep) import matplotlib.pylab as plt @@ -262,6 +268,13 @@ def plot(self, title=None, **kwargs): Any additional keyword arguments will be passed through to ``matplotlib.pylab.plot``. """ + warnings.warn( + ( + ".plot() will be removed in a future version." + "If you need help migrating, send us a message: " + "https://ploomber.io/community" + ) + ) import matplotlib.pylab as plt self.guess_plot_columns() @@ -303,7 +316,13 @@ def bar(self, key_word_sep=" ", title=None, **kwargs): Any additional keyword arguments will be passed through to ``matplotlib.pylab.bar``. """ - warnings.warn("Please use %sqlplot API") + warnings.warn( + ( + ".bar() will be removed in a future version," + "please use %sqlplot bar. If you need help migrating," + "send us a message: https://ploomber.io/community" + ) + ) import matplotlib.pylab as plt ax = plt.gca() From 9aae53335b8d544607cfaccd62d169da1d2b2965 Mon Sep 17 00:00:00 2001 From: tl3119 Date: Tue, 27 Jun 2023 17:39:50 -0400 Subject: [PATCH 4/6] Update run.py --- src/sql/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sql/run.py b/src/sql/run.py index 593bf3550..46644c069 100644 --- a/src/sql/run.py +++ b/src/sql/run.py @@ -236,7 +236,7 @@ def pie(self, key_word_sep=" ", title=None, **kwargs): warnings.warn( ( ".pie() will be removed in a future version," - "please use %sqlplot bar. If you need help migrating," + "please use %sqlplot pie. If you need help migrating," "send us a message: https://ploomber.io/community" ) ) From fdd9795ba387963000290f2d54258ba03de7fa9f Mon Sep 17 00:00:00 2001 From: tl3119 Date: Thu, 29 Jun 2023 17:43:01 -0400 Subject: [PATCH 5/6] Update test case --- CHANGELOG.md | 2 +- src/tests/test_run.py | 54 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c068c4ee6..14a5c0941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ * [Doc] Document --persist-replace in API section (#539) * [Fix] Fixed CI issue by updating `invalid_connection_string_duckdb` in `test_magic.py` (#631) * [Fix] Refactored `ResultSet` to lazy loading (#470) -* [Fix] Showed depcrecation warnings message for plot API ([#513](https://github.com/ploomber/jupysql/issues/513)) +* [Fix] Showed depcrecation warnings message for plot API (#513) * [Fix] Removed `WITH` when a snippet does not have a dependency (#657) ## 0.7.9 (2023-06-19) diff --git a/src/tests/test_run.py b/src/tests/test_run.py index ebfd97214..a79711974 100644 --- a/src/tests/test_run.py +++ b/src/tests/test_run.py @@ -78,9 +78,63 @@ def PolarsDataFrame(cls): def fetch_results(self, fetch_all=False): pass + @classmethod + def pie(self, key_word_sep=" ", title=None, **kwargs): + warnings.warn( + ( + ".pie() will be removed in a future version," + "please use %sqlplot pie. If you need help migrating," + "send us a message: https://ploomber.io/community" + ) + ) + + @classmethod + def bar(self, key_word_sep=" ", title=None, **kwargs): + warnings.warn( + ( + ".bar() will be removed in a future version," + "please use %sqlplot bar. If you need help migrating," + "send us a message: https://ploomber.io/community" + ) + ) + + @classmethod + def plot(self, key_word_sep=" ", title=None, **kwargs): + warnings.warn( + ( + ".plot() will be removed in a future version," + "If you need help migrating," + "send us a message: https://ploomber.io/community" + ) + ) + return ResultSet +def test_pie_warning(mock_resultset): + with warnings.catch_warnings(record=True) as warning_list: + rs = mock_resultset() + rs.pie() + rs.bar() + rs.plot() + assert len(warning_list) == 3 + assert str(warning_list[0].message) == ( + ".pie() will be removed in a future version," + "please use %sqlplot pie. If you need help migrating," + "send us a message: https://ploomber.io/community" + ) + assert str(warning_list[1].message) == ( + ".bar() will be removed in a future version," + "please use %sqlplot bar. If you need help migrating," + "send us a message: https://ploomber.io/community" + ) + assert str(warning_list[2].message) == ( + ".plot() will be removed in a future version," + "If you need help migrating," + "send us a message: https://ploomber.io/community" + ) + + @pytest.mark.parametrize( "dialect", [ From 976ddbb3dece9167cd0f375a077cdf6e026ab5db Mon Sep 17 00:00:00 2001 From: tl3119 Date: Fri, 30 Jun 2023 10:49:16 -0400 Subject: [PATCH 6/6] Update test case using pytest.parametrizera --- src/tests/test_run.py | 54 +++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/tests/test_run.py b/src/tests/test_run.py index a79711974..0e0666edf 100644 --- a/src/tests/test_run.py +++ b/src/tests/test_run.py @@ -111,28 +111,42 @@ def plot(self, key_word_sep=" ", title=None, **kwargs): return ResultSet -def test_pie_warning(mock_resultset): +@pytest.mark.parametrize( + "deprecated_warning", + [ + ( + "pie", + ( + ".pie() will be removed in a future version," + "please use %sqlplot pie. If you need help migrating," + "send us a message: https://ploomber.io/community" + ), + ), + ( + "bar", + ( + ".bar() will be removed in a future version," + "please use %sqlplot bar. If you need help migrating," + "send us a message: https://ploomber.io/community" + ), + ), + ( + "plot", + ( + ".plot() will be removed in a future version," + "If you need help migrating," + "send us a message: https://ploomber.io/community" + ), + ), + ], +) +def test_pie_warning(mock_resultset, deprecated_warning): + func_name, expected_warning = deprecated_warning with warnings.catch_warnings(record=True) as warning_list: rs = mock_resultset() - rs.pie() - rs.bar() - rs.plot() - assert len(warning_list) == 3 - assert str(warning_list[0].message) == ( - ".pie() will be removed in a future version," - "please use %sqlplot pie. If you need help migrating," - "send us a message: https://ploomber.io/community" - ) - assert str(warning_list[1].message) == ( - ".bar() will be removed in a future version," - "please use %sqlplot bar. If you need help migrating," - "send us a message: https://ploomber.io/community" - ) - assert str(warning_list[2].message) == ( - ".plot() will be removed in a future version," - "If you need help migrating," - "send us a message: https://ploomber.io/community" - ) + getattr(rs, func_name)() + assert len(warning_list) == 1 + assert str(warning_list[0].message) == expected_warning @pytest.mark.parametrize(