From c1f9cdf8d12a97067a4d6d131e08b88309d146f2 Mon Sep 17 00:00:00 2001 From: anupam-tiwari <40127722+anupam-tiwari@users.noreply.github.com> Date: Sun, 16 Jul 2023 18:24:28 -0400 Subject: [PATCH] Migrate user feedback to use display module (#735) * Empty-Commit * Empty-Commit * changelog * commit * commit * commit * commit * commit --------- Co-authored-by: Anupam --- CHANGELOG.md | 1 + src/sql/connection.py | 2 +- src/sql/magic.py | 10 ++++++---- src/sql/plot.py | 12 +++++++----- src/sql/run.py | 2 +- src/sql/util.py | 4 ++-- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23bc7b145..726848713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * [Doc] Re-organized sections. Adds section showing how to share notebooks via Ploomber Cloud * [Fix] Adding `--with` back because of issues with sqlglot query parser (#684) * [Fix] Improving << parsing logic (#610) +* [Fix] Migrate user feedback to use display module (#548) ## 0.7.9 (2023-06-19) diff --git a/src/sql/connection.py b/src/sql/connection.py index d5435055b..e70d7ae12 100644 --- a/src/sql/connection.py +++ b/src/sql/connection.py @@ -489,7 +489,7 @@ def close_all(cls, verbose=False): conn.close(key) if verbose: - print(f"Closing {key}") + display.message(f"Closing {key}") cls.connections = {} diff --git a/src/sql/magic.py b/src/sql/magic.py index 2ec092792..336d188ff 100644 --- a/src/sql/magic.py +++ b/src/sql/magic.py @@ -168,7 +168,7 @@ def __init__(self, shell): @validate("displaylimit") def _valid_displaylimit(self, proposal): if proposal["value"] is None: - print("displaylimit: Value None will be treated as 0 (no limit)") + display.message("displaylimit: Value None will be treated as 0 (no limit)") return 0 try: value = int(proposal["value"]) @@ -188,7 +188,9 @@ def _mutex_autopandas_autopolars(self, change): other = "autopolars" if change["name"] == "autopandas" else "autopandas" if getattr(self, other): setattr(self, other, False) - print(f"Disabled '{other}' since '{change['name']}' was enabled.") + display.message( + f"Disabled '{other}' since '{change['name']}' was enabled." + ) def check_random_arguments(self, line="", cell=""): # check only for cell magic @@ -411,7 +413,7 @@ def interactive_execute_wrapper(**kwargs): interactive_dict = {} for key in args.interact: interactive_dict[key] = local_ns[key] - print( + display.message( "Interactive mode, please interact with below " "widget(s) to control the variable" ) @@ -527,7 +529,7 @@ def interactive_execute_wrapper(**kwargs): result = result.dict() if self.feedback: - print( + display.message( "Returning data to local variables [{}]".format(", ".join(keys)) ) diff --git a/src/sql/plot.py b/src/sql/plot.py index 176e31b78..8ddbf9a3d 100644 --- a/src/sql/plot.py +++ b/src/sql/plot.py @@ -7,7 +7,7 @@ from sql.util import flatten from sqlalchemy.exc import ProgrammingError -from sql import exceptions +from sql import exceptions, display try: import matplotlib.pyplot as plt @@ -666,7 +666,7 @@ def _bar(table, column, with_=None, conn=None): x_ = column[0] height_ = column[1] - print(f"Removing NULLs, if there exists any from {x_} and {height_}") + display.message(f"Removing NULLs, if there exists any from {x_} and {height_}") template_ = """ select "{{x_}}" as x, "{{height_}}" as height @@ -685,7 +685,7 @@ def _bar(table, column, with_=None, conn=None): query = template.render(table=table, x_=x_, height_=height_) else: - print(f"Removing NULLs, if there exists any from {column}") + display.message(f"Removing NULLs, if there exists any from {column}") template_ = """ select "{{column}}" as x, count("{{column}}") as height @@ -850,7 +850,9 @@ def _pie(table, column, with_=None, conn=None): labels_ = column[0] size_ = column[1] - print(f"Removing NULLs, if there exists any from {labels_} and {size_}") + display.message( + f"Removing NULLs, if there exists any from {labels_} and {size_}" + ) template_ = """ select "{{labels_}}" as labels, "{{size_}}" as size @@ -865,7 +867,7 @@ def _pie(table, column, with_=None, conn=None): query = template.render(table=table, labels_=labels_, size_=size_) else: - print(f"Removing NULLs, if there exists any from {column}") + display.message(f"Removing NULLs, if there exists any from {column}") template_ = """ select "{{column}}" as x, count("{{column}}") as height diff --git a/src/sql/run.py b/src/sql/run.py index e6e76cd34..10de35609 100644 --- a/src/sql/run.py +++ b/src/sql/run.py @@ -529,7 +529,7 @@ def _commit(conn, config, manual_commit): with Session(conn.session) as session: session.commit() except sqlalchemy.exc.OperationalError: - print("The database does not support the COMMIT command") + display.message("The database does not support the COMMIT command") def is_postgres_or_redshift(dialect): diff --git a/src/sql/util.py b/src/sql/util.py index 3df5122cf..ce51eb851 100644 --- a/src/sql/util.py +++ b/src/sql/util.py @@ -4,7 +4,7 @@ import difflib from sql.connection import Connection from sql.store import store, _get_dependents_for_key -from sql import exceptions +from sql import exceptions, display import json SINGLE_QUOTE = "'" @@ -182,7 +182,7 @@ def strip_multiple_chars(string: str, chars: str) -> str: def is_saved_snippet(table: str) -> bool: if table in list(store): - print(f"Plotting using saved snippet : {table}") + display.message(f"Plotting using saved snippet : {table}") return True return False