Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecating legacy plot API #669

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions src/sql/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
tl3119 marked this conversation as resolved.
Show resolved Hide resolved
)
self.guess_pie_columns(xlabel_sep=key_word_sep)
import matplotlib.pylab as plt

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
68 changes: 68 additions & 0 deletions src/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down