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

513 deprecating legacy plot api #849

Closed
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 @@ -9,6 +9,7 @@
* [Fix] Improve error when passing a non-identifier to start a connection (#764)
* [Fix] Display a warning (instead of raising an error) if the `default` connection in the `.ini` file cannot start
* [Fix] Display a message instead of an error when `toml` isn't installed and `pyproject.toml` is found (#825)
* [Fix] Show deprecation warnings for legacy plot API (#513)

## 0.10.0 (2023-08-19)

Expand Down
27 changes: 27 additions & 0 deletions src/sql/run/resultset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from sql.run.table import CustomPrettyTable
from sql._current import _config_feedback_all

import warnings


class ResultSet(ColumnGuesserMixin):
"""
Expand Down Expand Up @@ -282,6 +284,14 @@ def pie(self, key_word_sep=" ", title=None, **kwargs):
Any additional keyword arguments will be passed
through to ``matplotlib.pylab.pie``.
"""
warnings.warn(
(
".pie() is deprecated and will be removed in a future version. "
"Use %sqlplot pie instead. "
"For more help, find us at https://ploomber.io/community "
),
UserWarning,
)
self.guess_pie_columns(xlabel_sep=key_word_sep)
import matplotlib.pylab as plt

Expand Down Expand Up @@ -310,6 +320,14 @@ def plot(self, title=None, **kwargs):
Any additional keyword arguments will be passed
through to ``matplotlib.pylab.plot``.
"""
warnings.warn(
(
".plot() is deprecated and will be removed in a future version. "
"For more help, find us at https://ploomber.io/community "
),
UserWarning,
)

import matplotlib.pylab as plt

self.guess_plot_columns()
Expand Down Expand Up @@ -351,6 +369,15 @@ def bar(self, key_word_sep=" ", title=None, **kwargs):
Any additional keyword arguments will be passed
through to ``matplotlib.pylab.bar``.
"""
warnings.warn(
(
".bar() is deprecated and will be removed in a future version. "
"Use %sqlplot bar instead. "
"For more help, find us at https://ploomber.io/community "
),
UserWarning,
)

import matplotlib.pylab as plt

ax = plt.gca()
Expand Down
55 changes: 55 additions & 0 deletions src/tests/test_resultset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from sql.run.resultset import ResultSet
from sql.connection.connection import IS_SQLALCHEMY_ONE

import warnings


@pytest.fixture
def config():
Expand Down Expand Up @@ -635,3 +637,56 @@ def test_doesnt_refresh_sqlaproxy_if_different_connection():
list(first_set)

assert id(first_set._sqlaproxy) == original_id


@pytest.fixture
def result_warnings():
df = pd.DataFrame({range(3), range(4, 7)}) # noqa
engine = sqlalchemy.create_engine("duckdb://")

conn = SQLAlchemyConnection(engine)
result = conn.raw_execute("select * from df")

yield result, conn
conn.close()


@pytest.fixture
def result_set_warnings(result_warnings, config):
result_set_warn, conn = result_warnings
return ResultSet(result_set_warn, config, statement="select * from df", conn=conn)


@pytest.mark.parametrize(
"function, expected_warning",
[
(
"pie",
(
".pie() is deprecated and will be removed in a future version. "
"Use %sqlplot pie instead. "
"For more help, find us at https://ploomber.io/community "
),
),
(
"bar",
(
".bar() is deprecated and will be removed in a future version. "
"Use %sqlplot bar instead. "
"For more help, find us at https://ploomber.io/community "
),
),
(
"plot",
(
".plot() is deprecated and will be removed in a future version. "
"For more help, find us at https://ploomber.io/community "
),
),
],
)
def test_deprecated_warnings(result_set_warnings, function, expected_warning):
with warnings.catch_warnings(record=True) as record:
getattr(result_set_warnings, function)()
assert len(record) == 1
assert str(record[0].message) == expected_warning
Loading