Skip to content

Commit

Permalink
PART 4
Browse files Browse the repository at this point in the history
  • Loading branch information
oualib committed Oct 2, 2024
1 parent ba390cf commit 96ed43d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
12 changes: 12 additions & 0 deletions verticapy/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ def set_option(key: str, value: Any = None) -> None:
[bool]
If set to ``True``, a loading bar is displayed
when using iterative functions.
- verbosity
[int]
API Verbosity, must be a value between 0 and 3.
0 (silent) | 1 (warning) | 2 (info) | 3 (debug)
value: object, optional
New value of the option.
Expand Down Expand Up @@ -758,3 +762,11 @@ def set_option(key: str, value: Any = None) -> None:

# Verbosity
register_option(Option("print_info", True, "", bool_validator))
register_option(
Option(
"verbosity",
2,
"",
in_validator([0, 1, 2, 3]),
)
)
14 changes: 11 additions & 3 deletions verticapy/_utils/_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ def print_message(
verbosity.
"""
mtype = mtype.lower().strip()
if mtype == "warning":
if mtype == "warning" and conf.get_option("verbosity") >= 1:
warnings.warn(message, Warning)
elif mtype == "print" and conf.get_option("print_info"):
elif (
mtype == "print"
and conf.get_option("print_info")
and conf.get_option("verbosity") >= 2
):
print(message)
elif mtype == "display" and conf.get_option("print_info"):
elif (
mtype == "display"
and conf.get_option("print_info")
and conf.get_option("verbosity") >= 2
):
display(HTML(message))
8 changes: 6 additions & 2 deletions verticapy/_utils/_sql/_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ def _executeSQL(
query = clean_query(query)

cursor = current_cursor()
if conf.get_option("sql_on") and print_time_sql:
if (
conf.get_option("sql_on") or (conf.get_option("verbosity") == 3)
) and print_time_sql:
print_query(query, title)
start_time = time.time()
if data:
Expand All @@ -183,7 +185,9 @@ def _executeSQL(
else:
cursor.execute(query)
elapsed_time = time.time() - start_time
if conf.get_option("time_on") and print_time_sql:
if (
conf.get_option("time_on") or (conf.get_option("verbosity") == 3)
) and print_time_sql:
print_time(elapsed_time)
if method == "fetchrow":
return cursor.fetchone()
Expand Down
4 changes: 2 additions & 2 deletions verticapy/core/tablesample/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ def read_sql(
"""
if _clean_query:
query = clean_query(query)
if conf.get_option("sql_on"):
if conf.get_option("sql_on") or (conf.get_option("verbosity") == 3):
print_query(query, title)
start_time = time.time()
cursor = _executeSQL(
Expand All @@ -1075,7 +1075,7 @@ def read_sql(
scale=elem[5],
)
elapsed_time = time.time() - start_time
if conf.get_option("time_on"):
if conf.get_option("time_on") or (conf.get_option("verbosity") == 3):
print_time(elapsed_time)
result = cursor.fetchall()
columns = [column[0] for column in cursor.description]
Expand Down

0 comments on commit 96ed43d

Please sign in to comment.