diff --git a/CHANGELOG.md b/CHANGELOG.md index dc526c203..2f653f5e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,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) * [Fix] Removed `WITH` when a snippet does not have a dependency (#657) ## 0.7.9 (2023-06-19) diff --git a/src/sql/run.py b/src/sql/run.py index e6e76cd34..f9b322f51 100644 --- a/src/sql/run.py +++ b/src/sql/run.py @@ -255,6 +255,13 @@ def pie(self, key_word_sep=" ", title=None, **kwargs): Any additional keyword arguments will be passed through to ``matplotlib.pylab.pie``. """ + 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" + ) + ) self.guess_pie_columns(xlabel_sep=key_word_sep) import matplotlib.pylab as plt @@ -283,6 +290,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() @@ -324,6 +338,13 @@ def bar(self, key_word_sep=" ", title=None, **kwargs): Any additional keyword arguments will be passed through to ``matplotlib.pylab.bar``. """ + 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() diff --git a/src/tests/test_run.py b/src/tests/test_run.py index ebfd97214..0e0666edf 100644 --- a/src/tests/test_run.py +++ b/src/tests/test_run.py @@ -78,9 +78,77 @@ 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 +@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() + getattr(rs, func_name)() + assert len(warning_list) == 1 + assert str(warning_list[0].message) == expected_warning + + @pytest.mark.parametrize( "dialect", [