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 #870

Merged
merged 12 commits into from
Sep 14, 2023
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* [Doc] Add chDB integration tutorial
* [Doc] Clarify the use of `pyproject.toml` and `connections.ini` in documentations (#850)
* [Fix] Fix result not displayed when `SUMMARIZE` argument is used in duckdb with a sqlalchemy connection (#836)
* [Fix] Show deprecation warnings for legacy plot API (#513)


## 0.10.1 (2023-08-30)

Expand Down
28 changes: 27 additions & 1 deletion src/sql/run/resultset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from html import unescape
from collections.abc import Iterable


import prettytable
import warnings

from sql.column_guesser import ColumnGuesserMixin
from sql.run.csv import CSVWriter, CSVResultDescriptor
Expand Down Expand Up @@ -282,6 +282,15 @@ 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 +319,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 +368,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
57 changes: 57 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,58 @@ def test_doesnt_refresh_sqlaproxy_if_different_connection():
list(first_set)

assert id(first_set._sqlaproxy) == original_id


@pytest.mark.parametrize(
"function, expected_warning, dataset",
[
(
"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 "
),
{
"x": [1, 2, 3],
"y": [4, 5, 6],
},
),
(
"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 "
),
{
"x": [1, 2, 3],
},
),
(
"plot",
(
".plot() is deprecated and will be removed in a future version. "
"For more help, find us at https://ploomber.io/community "
),
{
"x": [1, 2, 3],
},
),
],
)
def test_calling_legacy_plotting_functions_displays_warning(
config, function, expected_warning, dataset
):
df = pd.DataFrame(dataset) # noqa
engine = sqlalchemy.create_engine("duckdb://")
conn = SQLAlchemyConnection(engine)
result = conn.raw_execute("select * from df")

rs = ResultSet(result, config, statement="select * from df", conn=conn)

with warnings.catch_warnings(record=True) as record:
getattr(rs, function)()
edublancas marked this conversation as resolved.
Show resolved Hide resolved

assert len(record) == 1
assert str(record[0].message) == expected_warning
Loading