Skip to content

Commit

Permalink
adds deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bryannho committed Sep 7, 2023
1 parent f5a1163 commit 2a1817d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
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

0 comments on commit 2a1817d

Please sign in to comment.