From 66c50ffed4ad8025c9d1ce305fbe49284853d96b Mon Sep 17 00:00:00 2001 From: Badr Date: Wed, 2 Oct 2024 05:10:39 -0400 Subject: [PATCH 1/7] Verbosity - Implementing VerticaPy verbosity. [Only Part1 is implemented] --- verticapy/__init__.py | 4 +- verticapy/_config/validators.py | 29 ++++++------ verticapy/_utils/_display.py | 3 +- verticapy/_utils/_inspect_statistics.py | 3 +- verticapy/_utils/_logo.py | 3 +- verticapy/_utils/_parsers.py | 10 ++-- verticapy/_utils/_print.py | 29 ++++++++++++ verticapy/_utils/_sql/_display.py | 11 +++-- verticapy/_utils/_sql/_format.py | 26 +++++------ verticapy/_utils/_sql/_merge.py | 3 +- verticapy/connection/connect.py | 12 +++-- verticapy/connection/oauth_manager.py | 7 ++- verticapy/connection/write.py | 17 +++---- verticapy/core/parsers/all.py | 6 +-- verticapy/core/parsers/csv.py | 8 ++-- verticapy/core/parsers/json.py | 3 +- verticapy/core/parsers/shp.py | 3 +- verticapy/core/tablesample/base.py | 4 +- verticapy/core/vdataframe/_aggregate.py | 4 +- verticapy/core/vdataframe/_encoding.py | 8 ++-- verticapy/core/vdataframe/_fill.py | 8 ++-- verticapy/core/vdataframe/_filter.py | 18 ++++---- .../core/vdataframe/_machine_learning.py | 4 +- verticapy/core/vdataframe/_math.py | 5 +- verticapy/core/vdataframe/_plotting.py | 6 +-- verticapy/core/vdataframe/_scaler.py | 14 +++--- verticapy/core/vdataframe/_sys.py | 10 ++-- verticapy/core/vdataframe/base.py | 4 +- verticapy/jupyter/extensions/chart_magic.py | 4 +- verticapy/jupyter/extensions/sql_magic.py | 24 +++++----- .../model_selection/hp_tuning/cv.py | 27 +++++------ .../model_selection/kmeans.py | 3 +- .../model_selection/statistical_tests/ols.py | 13 +++--- .../model_selection/variables_selection.py | 29 ++++++------ .../vertica/automl/clustering.py | 7 +-- .../vertica/automl/supervised.py | 9 ++-- verticapy/machine_learning/vertica/base.py | 8 ++-- .../machine_learning/vertica/neighbors.py | 4 +- .../vertica/tensorflow/freeze_tf2_model.py | 45 ++++++++++-------- .../machine_learning/vertica/tsa/base.py | 3 +- .../machine_learning/vertica/tsa/ensemble.py | 3 +- verticapy/mlops/model_tracking/base.py | 4 +- .../vertica/collection/collection_tables.py | 15 +++--- .../vertica/collection/profile_export.py | 13 +++--- .../vertica/collection/profile_import.py | 7 +-- verticapy/performance/vertica/qprof.py | 46 +++++++++---------- verticapy/pipeline/_transform.py | 3 +- verticapy/pipeline/parser.py | 3 +- verticapy/plotting/_highcharts/scatter.py | 4 +- verticapy/plotting/_utils.py | 4 +- verticapy/plotting/base.py | 4 +- verticapy/sdk/vertica/udf/gen.py | 5 +- verticapy/sdk/vertica/udf/load.py | 4 +- verticapy/sql/dtypes.py | 4 +- verticapy/sql/geo/index.py | 4 +- verticapy/sql/insert.py | 4 +- 56 files changed, 310 insertions(+), 255 deletions(-) create mode 100644 verticapy/_utils/_print.py diff --git a/verticapy/__init__.py b/verticapy/__init__.py index 3c3313f1f..20fa58f33 100755 --- a/verticapy/__init__.py +++ b/verticapy/__init__.py @@ -37,8 +37,8 @@ __url__: str = "https://github.com/vertica/verticapy/" __license__: str = "Apache License, Version 2.0" __version__: str = "1.0.5" -__iteration__: int = 2 -__date__: str = "01102024" +__iteration__: int = 1 +__date__: str = "02102024" __last_commit__: str = "c4fa73aaaf54051fb35b325a5dd77573ba9b3f4c" __long_version__: str = f"{__version__}-{__iteration__}—{__date__}-{__last_commit__}" __codecov__: float = 0.84 diff --git a/verticapy/_config/validators.py b/verticapy/_config/validators.py index 415d82062..275f5374f 100755 --- a/verticapy/_config/validators.py +++ b/verticapy/_config/validators.py @@ -16,6 +16,7 @@ """ from typing import Any, Callable, Literal, Optional +from verticapy._utils._print import print_message from verticapy._typing import NoneType @@ -58,8 +59,8 @@ def bool_validator(val: bool) -> Literal[True]: try: bool_validator('Hello') except ValueError as e: - print('Error raised:') - print(e) + print_message('Error raised:') + print_message(e) .. seealso:: @@ -113,8 +114,8 @@ def in_validator(values: list) -> Callable[[Any], Literal[True]]: try: in_validator_ABC('D') except ValueError as e: - print('Error raised:') - print(e) + print_message('Error raised:') + print_message(e) .. seealso:: @@ -172,8 +173,8 @@ def optional_bool_validator(val: Optional[bool]) -> Literal[True]: try: optional_bool_validator('Hello') except ValueError as e: - print('Error raised:') - print(e) + print_message('Error raised:') + print_message(e) .. seealso:: @@ -227,8 +228,8 @@ def optional_positive_int_validator(val: Optional[int]) -> Literal[True]: try: optional_positive_int_validator(-3) except ValueError as e: - print('Error raised:') - print(e) + print_message('Error raised:') + print_message(e) .. seealso:: @@ -282,8 +283,8 @@ def optional_str_validator(val: Optional[str]) -> Literal[True]: try: optional_str_validator(7) except ValueError as e: - print('Error raised:') - print(e) + print_message('Error raised:') + print_message(e) .. seealso:: @@ -334,8 +335,8 @@ def str_validator(val: str) -> Literal[True]: try: str_validator(-1) except ValueError as e: - print('Error raised:') - print(e) + print_message('Error raised:') + print_message(e) .. seealso:: @@ -386,8 +387,8 @@ def st_positive_int_validator(val: int) -> Literal[True]: try: st_positive_int_validator(-1) except ValueError as e: - print('Error raised:') - print(e) + print_message('Error raised:') + print_message(e) .. seealso:: diff --git a/verticapy/_utils/_display.py b/verticapy/_utils/_display.py index 52eea9d77..ae129919a 100755 --- a/verticapy/_utils/_display.py +++ b/verticapy/_utils/_display.py @@ -16,7 +16,7 @@ """ import html import shutil -from typing import Optional +from typing import Literal, Optional import verticapy._config.config as conf from verticapy._typing import NoneType @@ -24,7 +24,6 @@ from verticapy._utils._sql._format import format_type from verticapy._utils._logo import verticapy_logo_html - def print_table( data_columns, is_finished: bool = True, diff --git a/verticapy/_utils/_inspect_statistics.py b/verticapy/_utils/_inspect_statistics.py index 1daf82a61..7a059c617 100644 --- a/verticapy/_utils/_inspect_statistics.py +++ b/verticapy/_utils/_inspect_statistics.py @@ -22,6 +22,7 @@ import verticapy as vp from verticapy._typing import PlottingObject, NoneType from verticapy._utils._object import create_new_vdf +from verticapy._utils._print import print_message if TYPE_CHECKING: from verticapy.core.vdataframe.base import vDataFrame @@ -240,7 +241,7 @@ def gen_rst_summary_table() -> str: from verticapy._utils._inspect_statistics import gen_rst_summary_table # Example. - print(gen_rst_summary_table()) + print_message(gen_rst_summary_table()) .. note:: diff --git a/verticapy/_utils/_logo.py b/verticapy/_utils/_logo.py index 2787fc805..ccb1d45ee 100755 --- a/verticapy/_utils/_logo.py +++ b/verticapy/_utils/_logo.py @@ -15,7 +15,6 @@ permissions and limitations under the License. """ - def verticapy_logo_html(size: str = "50%") -> str: """ Generates the HTML code @@ -88,7 +87,7 @@ def verticapy_logo_str() -> str: logo = verticapy_logo_str() # printing the result - print(logo) + print_message(logo) .. note:: diff --git a/verticapy/_utils/_parsers.py b/verticapy/_utils/_parsers.py index 8e74a7690..bfc2edd1d 100755 --- a/verticapy/_utils/_parsers.py +++ b/verticapy/_utils/_parsers.py @@ -17,9 +17,9 @@ import io import os from typing import List -import warnings import verticapy._config.config as conf +from verticapy._utils._print import print_message from verticapy._utils._sql._format import list_strip if conf.get_import_success("graphviz"): @@ -104,7 +104,7 @@ def get_header_names( "to CSV while retaining its indexes.\nTip: Use " "index=False when exporting with pandas.DataFrame.to_csv." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") return list_strip(file_header) @@ -183,7 +183,7 @@ def get_first_record_as_list(path: str, sep: str, record_terminator: str) -> Lis # with a first line that looks like # col1,col2,col3 cols = get_first_record_as_list('test.csv', ',', '\\n') - print(cols) + print_message(cols) # Should print # ['col1', 'col2', 'col3'] @@ -223,7 +223,7 @@ def read_first_record(path: str, record_terminator: str) -> str: # col1,col2,col3; # 100,abc,3.14; r = read_first_record('test.csv', ',', ';') - print(r) + print_message(r) # Should print # 'col1,col2,col3;' """ @@ -330,7 +330,7 @@ def parse_explain_graphviz(rows: list[str], display_trees: bool = True) -> list: if display_trees: for row in result: if isinstance(row, str) or not (conf.get_import_success("IPython")): - print(row) + print_message(row) else: display(row) return result diff --git a/verticapy/_utils/_print.py b/verticapy/_utils/_print.py new file mode 100644 index 000000000..39b4bcfb5 --- /dev/null +++ b/verticapy/_utils/_print.py @@ -0,0 +1,29 @@ +""" +Copyright (c) 2018-2024 Open Text or one of its +affiliates. Licensed under the Apache License, +Version 2.0 (the "License"); You may not use this +file except in compliance with the License. + +You may obtain a copy of the License at: +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in +writing, software distributed under the License is +distributed on an "AS IS" BASIS, WITHOUT WARRANTIES +OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing +permissions and limitations under the License. +""" +import warnings + +def print_message(message: str, mtype: Literal["auto", "warning"] = "auto") -> None: + """ + Prints the input message or warning. + This function is used to manage the + verbosity. + """ + mtype = mtype.lower().strip() + if mtype == "warning": + warnings.warn(message, Warning) + elif mtype == "auto": + print_message(message) \ No newline at end of file diff --git a/verticapy/_utils/_sql/_display.py b/verticapy/_utils/_sql/_display.py index f3042a44a..ff3376bd6 100755 --- a/verticapy/_utils/_sql/_display.py +++ b/verticapy/_utils/_sql/_display.py @@ -18,6 +18,7 @@ from typing import Optional import verticapy._config.config as conf +from verticapy._utils._print import print_message from verticapy._utils._sql._format import clean_query, indent_vpy_sql if conf.get_import_success("IPython"): @@ -68,9 +69,9 @@ def print_query(query: str, title: Optional[str] = None) -> None: query_print = query_print.replace("\n", "
").replace(" ", "   ") display(HTML(query_print)) else: - print(f"$ {title} $\n") - print(query_print) - print("-" * int(screen_columns) + "\n") + print_message(f"$ {title} $\n") + print_message(query_print) + print_message("-" * int(screen_columns) + "\n") def print_time(elapsed_time: float) -> None: @@ -105,5 +106,5 @@ def print_time(elapsed_time: float) -> None: if conf.get_import_success("IPython"): display(HTML(f"
Execution: {round(elapsed_time, 3)}s
")) else: - print(f"Execution: {round(elapsed_time, 3)}s") - print("-" * int(screen_columns) + "\n") + print_message(f"Execution: {round(elapsed_time, 3)}s") + print_message("-" * int(screen_columns) + "\n") diff --git a/verticapy/_utils/_sql/_format.py b/verticapy/_utils/_sql/_format.py index 858a9ed86..c98ec9f01 100755 --- a/verticapy/_utils/_sql/_format.py +++ b/verticapy/_utils/_sql/_format.py @@ -15,7 +15,6 @@ permissions and limitations under the License. """ import re -import warnings from typing import Any, Iterable, Literal, Optional import numpy as np @@ -24,6 +23,7 @@ import verticapy._config.config as conf from verticapy._utils._object import read_pd +from verticapy._utils._print import print_message from verticapy._utils._sql._cast import to_dtype_category from verticapy._typing import NoneType, SQLColumns, SQLExpression from verticapy.errors import ParsingError @@ -554,8 +554,8 @@ def _format_keys( sql, html_sql = _format_keys( SQL_KEYWORDS, sql, html_sql, KEYWORDS_TAG_L, KEYWORDS_TAG_R ) - print(sql) - print(html_sql) + print_message(sql) + print_message(html_sql) .. note:: @@ -700,7 +700,7 @@ def format_query( if indent_sql: res = indent_vpy_sql(res) if print_sql: - print(res) + print_message(res) if only_html: return html_res elif display_success: @@ -748,7 +748,7 @@ def clean_query(query: SQLExpression) -> SQLExpression: sql += "subtable; -- simple query example" # Example. - print(clean_query(sql)) + print_message(clean_query(sql)) .. note:: @@ -803,7 +803,7 @@ def erase_comment(query: SQLExpression) -> SQLExpression: sql += "subtable; -- simple query example" # Example. - print(erase_comment(sql)) + print_message(erase_comment(sql)) .. note:: @@ -847,7 +847,7 @@ def erase_label(query: SQLExpression) -> SQLExpression: sql += "subtable; -- simple query example" # Example. - print(erase_label(sql)) + print_message(erase_label(sql)) .. note:: @@ -892,7 +892,7 @@ def extract_subquery(query: SQLExpression) -> SQLExpression: sql += "subtable -- simple query example) subtable2;" # Example. - print(extract_subquery(sql)) + print_message(extract_subquery(sql)) .. note:: @@ -941,7 +941,7 @@ def extract_and_rename_subquery(query: SQLExpression, alias: str) -> SQLExpressi sql += "subtable -- simple query example) subtable2;" # Example. - print( + print_message( extract_and_rename_subquery( sql, alias = 'new_alias', @@ -1252,7 +1252,7 @@ def indent_vpy_sql(query: SQLExpression) -> SQLExpression: sql += "subtable; -- simple query example" # Example. - print(indent_vpy_sql(sql)) + print_message(indent_vpy_sql(sql)) .. note:: @@ -1447,7 +1447,7 @@ def replace_label( sql += "subtable; -- simple query example" # Example. - print( + print_message( indent_vpy_sql( sql, new_label = 'label_test', @@ -1532,7 +1532,7 @@ def replace_vars_in_query(query: SQLExpression, locals_dict: dict) -> SQLExpress } # Example. - print(replace_vars_in_query(sql, locals_dict = vars)) + print_message(replace_vars_in_query(sql, locals_dict = vars)) .. note:: @@ -1574,7 +1574,7 @@ def replace_vars_in_query(query: SQLExpression, locals_dict: dict) -> SQLExpress warning_message = ( f"Failed to replace variables in the query.\nError: {e}" ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") fail = True if not fail: object_type = None diff --git a/verticapy/_utils/_sql/_merge.py b/verticapy/_utils/_sql/_merge.py index 52a985299..7527e7f1a 100755 --- a/verticapy/_utils/_sql/_merge.py +++ b/verticapy/_utils/_sql/_merge.py @@ -16,6 +16,7 @@ """ from typing import Optional +from verticapy._utils._print import print_message from verticapy._utils._sql._format import format_type, quote_ident @@ -565,7 +566,7 @@ def gen_coalesce(group_dict: dict) -> str: # Creating the dictionary. d = group_similar_names(names, skip_word = word) - print(d) + print_message(d) # Example gen_coalesce(d) diff --git a/verticapy/connection/connect.py b/verticapy/connection/connect.py index 42e190606..d12db450e 100755 --- a/verticapy/connection/connect.py +++ b/verticapy/connection/connect.py @@ -22,6 +22,8 @@ from vertica_python.vertica.connection import Connection import verticapy._config.config as conf +from verticapy._utils._print import print_message + from verticapy.connection.errors import ConnectionError, OAuthTokenRefreshError from verticapy.connection.global_connection import ( get_global_connection, @@ -143,9 +145,9 @@ def connect(section: str, dsn: Optional[str] = None) -> None: vertica_connection(section, dsn, config=None), section, dsn ) if conf.get_option("print_info"): - print("Connected Successfully!") + print_message("Connected Successfully!") except OAuthTokenRefreshError as error: - print( + print_message( "Access Denied: Your authentication credentials are incorrect or have expired. Please retry" ) new_connection( @@ -156,12 +158,12 @@ def connect(section: str, dsn: Optional[str] = None) -> None: vertica_connection(section, dsn, config=None), section, dsn ) if conf.get_option("print_info"): - print("Connected Successfully!") + print_message("Connected Successfully!") except OAuthTokenRefreshError as error: - print("Error persists:") + print_message("Error persists:") raise error except ConnectionError as error: - print( + print_message( "A connection error occured. Common reasons may be an invalid host, port, or, if requiring " "OAuth and token refresh, this may be due to an incorrect or malformed token url." ) diff --git a/verticapy/connection/oauth_manager.py b/verticapy/connection/oauth_manager.py index 2bbe557c0..a00b27b4e 100644 --- a/verticapy/connection/oauth_manager.py +++ b/verticapy/connection/oauth_manager.py @@ -18,12 +18,11 @@ from __future__ import print_function, division, absolute_import, annotations import requests -import warnings -from urllib3.poolmanager import PoolManager from requests.adapters import HTTPAdapter +from urllib3.poolmanager import PoolManager - +from verticapy._utils._print import print_message from verticapy.connection.errors import ( OAuthTokenRefreshError, OAuthConfigurationError, @@ -66,7 +65,7 @@ def set_config(self, configs) -> None: for k, v in configs.items(): if k not in valid_keys: invalid_key = f"Unrecognized OAuth config property: {k}" - warnings.warn(invalid_key) + print_message(invalid_key, "Warning") continue if v is None or v == "": # ignore empty value continue diff --git a/verticapy/connection/write.py b/verticapy/connection/write.py index 2398cb9eb..57963640a 100755 --- a/verticapy/connection/write.py +++ b/verticapy/connection/write.py @@ -16,10 +16,11 @@ """ from getpass import getpass -import warnings import vertica_python import verticapy._config.config as conf +from verticapy._utils._print import print_message + from verticapy.connection.errors import ConnectionError, OAuthTokenRefreshError from verticapy.connection.global_connection import get_global_connection from verticapy.connection.oauth_manager import OAuthManager @@ -182,7 +183,7 @@ def delete_connection(name: str) -> bool: return True else: - warnings.warn(f"The connection {name} does not exist.", Warning) + print_message(f"The connection {name} does not exist.", "Warning") return False @@ -294,7 +295,7 @@ def new_connection( def _printInfo(info): if doPrintInfo: - print(info) + print_message(info) path = get_connection_file() confparser = get_confparser() @@ -334,7 +335,7 @@ def _printInfo(info): conn_info["oauth_access_token"] = oauth_manager.do_token_refresh() conn_info["oauth_refresh_token"] = oauth_manager.refresh_token except OAuthTokenRefreshError as error: - print("An error occured while refreshing your OAuth token") + print_message("An error occured while refreshing your OAuth token") raise error for c in conn_info: @@ -354,7 +355,7 @@ def _printInfo(info): vertica_python.connect(**read_dsn(name, path)), name, path ) except OAuthTokenRefreshError as e: - print( + print_message( "Access Denied: Your authentication credentials are incorrect or have expired. Please retry" ) new_connection( @@ -365,12 +366,12 @@ def _printInfo(info): vertica_python.connect(**read_dsn(name, path)), name, path ) if doPrintInfo: - print("Connected Successfully!") + print_message("Connected Successfully!") except OAuthTokenRefreshError as error: - print("Error persists:") + print_message("Error persists:") raise error except ConnectionError as error: - print( + print_message( "A connection error occured. Common reasons may be an invalid host, port, or, if requiring " "OAuth and token refresh, this may be due to an incorrect or malformed token url." ) diff --git a/verticapy/core/parsers/all.py b/verticapy/core/parsers/all.py index 9ad29c60f..cf906e383 100755 --- a/verticapy/core/parsers/all.py +++ b/verticapy/core/parsers/all.py @@ -14,10 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. """ -import warnings from typing import Optional import verticapy._config.config as conf +from verticapy._utils._gen import gen_tmp_name +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import ( clean_query, @@ -25,7 +26,6 @@ format_type, quote_ident, ) -from verticapy._utils._gen import gen_tmp_name from verticapy._utils._sql._sys import _executeSQL from verticapy._utils._sql._vertica_version import check_minimum_version from verticapy.errors import ExtensionError @@ -476,7 +476,7 @@ def read_file( extract_col_dt = extract_col_dt_from_query(result[0], col) if extract_col_dt is None: warning_message = f"The column '{col}' was not found.\nIt will be skipped." - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") else: column, ctype = extract_col_dt result[0] = result[0].replace( diff --git a/verticapy/core/parsers/csv.py b/verticapy/core/parsers/csv.py index 05966c81a..9dbfeb0a0 100755 --- a/verticapy/core/parsers/csv.py +++ b/verticapy/core/parsers/csv.py @@ -15,15 +15,15 @@ permissions and limitations under the License. """ import os -import warnings from typing import Optional from vertica_python.errors import QueryError import verticapy._config.config as conf from verticapy._typing import NoneType -from verticapy._utils._parsers import get_header_names, guess_sep from verticapy._utils._gen import gen_tmp_name +from verticapy._utils._parsers import get_header_names, guess_sep +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import ( clean_query, @@ -732,7 +732,7 @@ def read_csv( "Parameters 'header_names' and 'dtype' are both defined. " "Only 'dtype' will be used." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") basename = ".".join(path.split("/")[-1].split(".")[0:-1]) if gen_tmp_table_name and temporary_local_table and not table_name: table_name = gen_tmp_name(name=basename) @@ -942,7 +942,7 @@ def read_csv( and not temporary_local_table and conf.get_option("print_info") ): - print(f"The table {input_relation} has been successfully created.") + print_message(f"The table {input_relation} has been successfully created.") return vDataFrame(table_name, schema=schema) diff --git a/verticapy/core/parsers/json.py b/verticapy/core/parsers/json.py index fe911ef93..404b7c308 100755 --- a/verticapy/core/parsers/json.py +++ b/verticapy/core/parsers/json.py @@ -22,6 +22,7 @@ import verticapy._config.config as conf from verticapy._typing import NoneType from verticapy._utils._gen import gen_tmp_name +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import ( quote_ident, @@ -799,7 +800,7 @@ def read_json( title="Creating table.", ) if not temporary_local_table and conf.get_option("print_info"): - print(f"The table {input_relation} has been successfully created.") + print_message(f"The table {input_relation} has been successfully created.") else: column_name_dtype = {} for elem in column_name: diff --git a/verticapy/core/parsers/shp.py b/verticapy/core/parsers/shp.py index 80e639585..ef33d3536 100755 --- a/verticapy/core/parsers/shp.py +++ b/verticapy/core/parsers/shp.py @@ -17,6 +17,7 @@ from typing import Optional import verticapy._config.config as conf +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._sys import _executeSQL from verticapy.errors import ExtensionError @@ -125,5 +126,5 @@ def read_shp( title="Ingesting the data.", ) if conf.get_option("print_info"): - print(f'The table "{schema}"."{table_name}" has been successfully created.') + print_message(f'The table "{schema}"."{table_name}" has been successfully created.') return vDataFrame(table_name, schema=schema) diff --git a/verticapy/core/tablesample/base.py b/verticapy/core/tablesample/base.py index a35f5203f..4a3ca61e2 100644 --- a/verticapy/core/tablesample/base.py +++ b/verticapy/core/tablesample/base.py @@ -139,7 +139,7 @@ class TableSample: tb.to_pandas() # Exporting to SQL. - print(tb.to_sql()) + print_message(tb.to_sql()) .. note:: @@ -1587,7 +1587,7 @@ def to_sql(self) -> str: .. ipython:: python - print(tb.to_sql()) + print_message(tb.to_sql()) .. seealso:: diff --git a/verticapy/core/vdataframe/_aggregate.py b/verticapy/core/vdataframe/_aggregate.py index e234dedd2..648d1dbb0 100755 --- a/verticapy/core/vdataframe/_aggregate.py +++ b/verticapy/core/vdataframe/_aggregate.py @@ -17,7 +17,6 @@ import decimal import multiprocessing from typing import Literal, Optional, Union -import warnings from tqdm.auto import tqdm @@ -35,6 +34,7 @@ ) from verticapy._utils._map import verticapy_agg_name from verticapy._utils._object import create_new_vdf +from verticapy._utils._print import print_message from verticapy._utils._sql._cast import to_varchar from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import ( @@ -1028,7 +1028,7 @@ def describe( "\nTo get statistical information about all different " "variables, please use the parameter method = 'categorical'." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") for column in columns: if column not in col_to_compute: values["index"] += [column.replace('"', "")] diff --git a/verticapy/core/vdataframe/_encoding.py b/verticapy/core/vdataframe/_encoding.py index 06fee2e90..8be3ba38c 100755 --- a/verticapy/core/vdataframe/_encoding.py +++ b/verticapy/core/vdataframe/_encoding.py @@ -16,13 +16,13 @@ """ import copy import math -import warnings from typing import Literal, Optional, TYPE_CHECKING import verticapy._config.config as conf from verticapy._typing import PythonNumber, SQLColumns from verticapy._utils._gen import gen_tmp_name from verticapy._utils._object import get_vertica_mllib, create_new_vdc +from verticapy._utils._print import print_message from verticapy._utils._sql._cast import to_varchar from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type @@ -354,7 +354,7 @@ def one_hot_encode( "'max_cardinality' to solve this issue or use " "directly the vDataColumn one_hot_encode method." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") return self get_dummies = one_hot_encode @@ -1495,7 +1495,7 @@ def label_encode(self) -> "vDataFrame": warning_message = ( "label_encode is only available for categorical variables." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") else: distinct_elements = self.distinct() expr = ["DECODE({}"] @@ -1647,5 +1647,5 @@ def mean_encode(self, response: str) -> "vDataFrame": f"using a mean encoding with {response} as Response Column." ) if conf.get_option("print_info"): - print("The mean encoding was successfully done.") + print_message("The mean encoding was successfully done.") return self._parent diff --git a/verticapy/core/vdataframe/_fill.py b/verticapy/core/vdataframe/_fill.py index 65d228f79..c8bee551c 100755 --- a/verticapy/core/vdataframe/_fill.py +++ b/verticapy/core/vdataframe/_fill.py @@ -16,7 +16,6 @@ """ import copy import datetime -import warnings from typing import Literal, Optional, Union, TYPE_CHECKING from vertica_python.errors import QueryError @@ -30,6 +29,7 @@ SQLColumns, ) from verticapy._utils._object import create_new_vdf +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type, quote_ident from verticapy._utils._sql._sys import _executeSQL @@ -881,7 +881,7 @@ def fillna( f"The vDataColumn {self} has no mode " "(only missing values).\nNothing was filled." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") return self._parent if isinstance(val, str): val = val.replace("'", "''") @@ -997,13 +997,13 @@ def fillna( total = int(total) conj = "s were " if total > 1 else " was " if conf.get_option("print_info"): - print(f"{total} element{conj}filled.") + print_message(f"{total} element{conj}filled.") self._parent._add_to_history( f"[Fillna]: {total} {self} missing value{conj} filled." ) else: if conf.get_option("print_info"): - print("Nothing was filled.") + print_message("Nothing was filled.") self._transf = [t for t in copy_trans] for s in sauv: self._catalog[s] = sauv[s] diff --git a/verticapy/core/vdataframe/_filter.py b/verticapy/core/vdataframe/_filter.py index a57374869..254c16fa9 100755 --- a/verticapy/core/vdataframe/_filter.py +++ b/verticapy/core/vdataframe/_filter.py @@ -16,7 +16,6 @@ """ import copy import random -import warnings from typing import Literal, Optional, Union, TYPE_CHECKING from collections.abc import Iterable @@ -32,6 +31,7 @@ TimeInterval, ) from verticapy._utils._object import create_new_vdf +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import clean_query, format_type, quote_ident from verticapy._utils._sql._sys import _executeSQL @@ -860,7 +860,7 @@ def drop_duplicates(self, columns: Optional[SQLColumns] = None) -> "vDataFrame": self.filter(f'"{name}" = 1') self._vars["exclude_columns"] += [f'"{name}"'] elif conf.get_option("print_info"): - print("No duplicates detected.") + print_message("No duplicates detected.") return self @save_verticapy_logs @@ -1004,10 +1004,10 @@ def dropna(self, columns: Optional[SQLColumns] = None) -> "vDataFrame": if conf.get_option("print_info"): total -= self.shape()[0] if total == 0: - print("Nothing was filtered.") + print_message("Nothing was filtered.") else: conj = "s were " if total > 1 else " was " - print(f"{total} element{conj}filtered.") + print_message(f"{total} element{conj}filtered.") return self @save_verticapy_logs @@ -1154,13 +1154,13 @@ def filter( count -= self.shape()[0] if count > 0: if conf.get_option("print_info"): - print(f"{count} element{conj}filtered") + print_message(f"{count} element{conj}filtered") self._add_to_history( f"[Filter]: {count} element{conj}filtered " f"using the filter '{conditions}'" ) elif conf.get_option("print_info"): - print("Nothing was filtered.") + print_message("Nothing was filtered.") else: max_pos = 0 columns_tmp = copy.deepcopy(self._vars["columns"]) @@ -1188,7 +1188,7 @@ def filter( f"The expression '{conditions}' is incorrect.\n" "Nothing was filtered." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") if raise_error: raise (e) return self @@ -1197,7 +1197,7 @@ def filter( self._vars["count"] = new_count conj = "s were " if count > 1 else " was " if conf.get_option("print_info") and "print_info" not in kwargs: - print(f"{count} element{conj}filtered.") + print_message(f"{count} element{conj}filtered.") conditions_clean = clean_query(conditions) self._add_to_history( f"[Filter]: {count} element{conj}filtered using " @@ -1206,7 +1206,7 @@ def filter( else: del self._vars["where"][-1] if conf.get_option("print_info") and "print_info" not in kwargs: - print("Nothing was filtered.") + print_message("Nothing was filtered.") return self @save_verticapy_logs diff --git a/verticapy/core/vdataframe/_machine_learning.py b/verticapy/core/vdataframe/_machine_learning.py index 3beb404e7..8426b8786 100755 --- a/verticapy/core/vdataframe/_machine_learning.py +++ b/verticapy/core/vdataframe/_machine_learning.py @@ -16,7 +16,6 @@ """ import math import random -import warnings from itertools import combinations_with_replacement from typing import Literal, Optional, Union, TYPE_CHECKING @@ -25,6 +24,7 @@ import verticapy._config.config as conf from verticapy._typing import PythonScalar, SQLColumns from verticapy._utils._object import create_new_vdf +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type, quote_ident from verticapy._utils._sql._sys import _executeSQL @@ -695,7 +695,7 @@ def chaid_columns( f"vDataColumn '{col}' has a too high cardinality " f"(> {max_cardinality}). This vDataColumn was ignored." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") for col in remove_cols: columns_tmp.remove(col) return columns_tmp diff --git a/verticapy/core/vdataframe/_math.py b/verticapy/core/vdataframe/_math.py index c44a7a124..2e6f67829 100755 --- a/verticapy/core/vdataframe/_math.py +++ b/verticapy/core/vdataframe/_math.py @@ -24,6 +24,7 @@ from verticapy._utils._gen import gen_name from verticapy._utils._map import verticapy_agg_name from verticapy._utils._object import create_new_vdf +from verticapy._utils._print import print_message from verticapy._utils._sql._cast import to_category from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type, quote_ident @@ -415,7 +416,7 @@ def analytic( "sem", ) or ("%" in func): if order_by and not conf.get_option("print_info"): - print( + print_message( f"\u26A0 '{func}' analytic method doesn't need an " "order by clause, it was ignored" ) @@ -605,7 +606,7 @@ def analytic( ) elif func in ("corr", "cov", "beta"): if order_by: - print( + print_message( f"\u26A0 '{func}' analytic method doesn't need an " "order by clause, it was ignored" ) diff --git a/verticapy/core/vdataframe/_plotting.py b/verticapy/core/vdataframe/_plotting.py index 99d6c9ede..05ce38fa5 100755 --- a/verticapy/core/vdataframe/_plotting.py +++ b/verticapy/core/vdataframe/_plotting.py @@ -16,13 +16,11 @@ """ import math -import warnings from collections.abc import Iterable from typing import Callable, Literal, Optional, Union import numpy as np import verticapy._config.config as conf -from verticapy._utils._object import get_vertica_mllib from verticapy._typing import ( ArrayLike, ColorType, @@ -34,6 +32,8 @@ SQLColumns, ) from verticapy._utils._gen import gen_tmp_name +from verticapy._utils._object import get_vertica_mllib +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type from verticapy._utils._sql._sys import _executeSQL @@ -3752,7 +3752,7 @@ def hist( f"The Virtual Column {self._alias} is not " "numerical. A bar chart will be drawn instead." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") if by: return self._parent.bar( columns=[self._alias, by], diff --git a/verticapy/core/vdataframe/_scaler.py b/verticapy/core/vdataframe/_scaler.py index f29ce5c32..c680cc8ec 100755 --- a/verticapy/core/vdataframe/_scaler.py +++ b/verticapy/core/vdataframe/_scaler.py @@ -16,13 +16,13 @@ """ import copy import math -import warnings from typing import Literal, Optional, TYPE_CHECKING from vertica_python.errors import QueryError import verticapy._config.config as conf from verticapy._typing import NoneType, SQLColumns +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type from verticapy._utils._sql._sys import _executeSQL @@ -195,7 +195,7 @@ def scale( f"The vDataColumn {column} was skipped.\n" "Scaler only accept numerical data types." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") return self normalize = scale @@ -356,7 +356,7 @@ def scale( if self.isbool(): warning_message = "Scaler doesn't work on booleans" - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") elif self.isnum(): if method == "zscore": @@ -368,7 +368,7 @@ def scale( f"Can not scale {self} using a " "Z-Score - The Standard Deviation is null !" ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") return self elif (n == 1) and (self._parent[by[0]].nunique() < 50): try: @@ -465,7 +465,7 @@ def scale( "parameter 'by' is empty\nIf you want to scale the data by " "grouping by elements, please use a method in zscore|minmax" ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") return self mad, med = self.aggregate(["mad", "approx_median"]).values[self._alias] mad *= 1.4826 @@ -485,7 +485,7 @@ def scale( f"Can not scale {self} using a " "Robust Z-Score - The MAD is null !" ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") return self elif method == "minmax": @@ -497,7 +497,7 @@ def scale( f"Can not scale {self} using " "the MIN and the MAX. MAX = MIN !" ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") return self elif n == 1: try: diff --git a/verticapy/core/vdataframe/_sys.py b/verticapy/core/vdataframe/_sys.py index bfb77a53a..f1af0f75a 100755 --- a/verticapy/core/vdataframe/_sys.py +++ b/verticapy/core/vdataframe/_sys.py @@ -17,13 +17,13 @@ import copy import sys import time -import warnings from typing import Any, Optional, Union, TYPE_CHECKING import verticapy._config.config as conf from verticapy._typing import NoneType, SQLColumns from verticapy._utils._map import verticapy_agg_name from verticapy._utils._object import create_new_vdc +from verticapy._utils._print import print_message from verticapy._utils._sql._cast import to_varchar from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type, indent_vpy_sql, quote_ident @@ -269,7 +269,7 @@ def _get_sort_syntax(self, columns: Union[dict, SQLColumns]) -> str: f"Method of {column_name} must be in (asc, desc), " f"found '{columns[col].lower()}'\nThis column was ignored." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") else: order_by += [f"{column_name} {columns[col].upper()}"] else: @@ -404,7 +404,7 @@ def current_relation(self, reindent: bool = True, split: bool = False) -> str: .. ipython:: python - print(vdf.current_relation()) + print_message(vdf.current_relation()) If we make any changes to the :py:class:`~vDataFrame`, those will also be reflected in the ``current_relation``. @@ -418,7 +418,7 @@ def current_relation(self, reindent: bool = True, split: bool = False) -> str: .. ipython:: python - print(vdf.current_relation()) + print_message(vdf.current_relation()) .. seealso:: @@ -789,7 +789,7 @@ def explain(self, digraph: bool = False) -> str: .. ipython:: python - print(vdf.explain()) + print_message(vdf.explain()) .. seealso:: diff --git a/verticapy/core/vdataframe/base.py b/verticapy/core/vdataframe/base.py index ff555c398..465bad6d0 100755 --- a/verticapy/core/vdataframe/base.py +++ b/verticapy/core/vdataframe/base.py @@ -16,7 +16,6 @@ """ import collections from typing import Literal, Optional, Union -import warnings import numpy as np @@ -25,6 +24,7 @@ from verticapy.connection.global_connection import get_global_connection from verticapy._typing import SQLColumns from verticapy._utils._object import read_pd +from verticapy._utils._print import print_message from verticapy._utils._sql._cast import to_category from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._check import is_longvar, is_dql @@ -689,7 +689,7 @@ def __init__( "resolve this issue, provide aliases to your " "queries." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") self._vars["has_dpnames"] = True # Creating the vDataColumns diff --git a/verticapy/jupyter/extensions/chart_magic.py b/verticapy/jupyter/extensions/chart_magic.py index 4a0672e46..f8530b1d8 100644 --- a/verticapy/jupyter/extensions/chart_magic.py +++ b/verticapy/jupyter/extensions/chart_magic.py @@ -16,7 +16,6 @@ """ import time -import warnings from typing import Optional, Literal, Union from IPython.core.magic import needs_local_scope @@ -26,6 +25,7 @@ import verticapy._config.config as conf from verticapy._typing import PlottingObject +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import clean_query, replace_vars_in_query @@ -721,7 +721,7 @@ def chart_magic( warning_message = ( f"\u26A0 Warning : The option '{option}' doesn't exist - skipping." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") if "-f" in options and "-c" in options: raise ValueError( diff --git a/verticapy/jupyter/extensions/sql_magic.py b/verticapy/jupyter/extensions/sql_magic.py index 9eac31e99..4f7359f40 100644 --- a/verticapy/jupyter/extensions/sql_magic.py +++ b/verticapy/jupyter/extensions/sql_magic.py @@ -25,7 +25,6 @@ ## import re import time -import warnings from typing import Optional, TYPE_CHECKING from IPython.core.magic import needs_local_scope @@ -34,6 +33,7 @@ import verticapy._config.config as conf from verticapy._utils._object import create_new_vdf from verticapy._utils._parsers import parse_explain_graphviz +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._check import is_procedure from verticapy._utils._sql._dblink import replace_external_queries @@ -679,7 +679,7 @@ def sql_magic( .. ipython:: python file = open("titanic_age_clean.csv", "r") - print(file.read()) + print_message(file.read()) file.close() To export the results of @@ -718,7 +718,7 @@ def sql_magic( .. ipython:: python file = open("titanic_age_clean.json", "r") - print(file.read()) + print_message(file.read()) file.close() Execute SQL files @@ -822,7 +822,7 @@ def sql_magic( f"\u26A0 Warning : The option '{option}' doesn't " "exist, it was skipped." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") if "-f" in options and "-c" in options: raise ValueError( @@ -843,7 +843,7 @@ def sql_magic( # Case when it is a procedure if is_procedure(queries): current_cursor().execute(queries) - print("CREATE") + print_message("CREATE") return # Cleaning the Query @@ -865,7 +865,7 @@ def sql_magic( ) if external_queries: - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") n, i, all_split = len(queries), 0, [] @@ -970,13 +970,13 @@ def sql_magic( in error and "DBLINK" in error ): - print(query_type) + print_message(query_type) elif error: raise QueryError(error) elif conf.get_option("print_info"): - print(query_type) + print_message(query_type) else: error = "" @@ -1023,13 +1023,13 @@ def sql_magic( query, method="fetchfirstelem", print_time_sql=False ) if final_result and conf.get_option("print_info"): - print(final_result) + print_message(final_result) elif ( query_subtype.upper().startswith(SPECIAL_WORDS) ) and conf.get_option("print_info"): - print(query_subtype.upper()) + print_message(query_subtype.upper()) elif conf.get_option("print_info"): - print(query_type) + print_message(query_type) except Exception as e: error = str(e) @@ -1042,7 +1042,7 @@ def sql_magic( and "DBLINK" in error ): if conf.get_option("print_info"): - print(query_type) + print_message(query_type) elif error: raise QueryError(error) diff --git a/verticapy/machine_learning/model_selection/hp_tuning/cv.py b/verticapy/machine_learning/model_selection/hp_tuning/cv.py index 1bccba475..6dd982943 100755 --- a/verticapy/machine_learning/model_selection/hp_tuning/cv.py +++ b/verticapy/machine_learning/model_selection/hp_tuning/cv.py @@ -24,6 +24,7 @@ import verticapy._config.config as conf from verticapy._typing import PythonNumber, PythonScalar, SQLColumns, SQLRelation from verticapy._utils._gen import gen_tmp_name +from verticapy._utils._print import print_message from verticapy._utils._sql._format import format_type from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._sys import _executeSQL @@ -1078,7 +1079,7 @@ def grid_search_cv( ) ] if print_info: - print( + print_message( f"Model: {str(estimator.__class__).split('.')[-1][:-2]}; " f"Parameters: {config}; \033[91mTest_score: " f"{current_cv[0][keys[1]][cv]}\033[0m; \033[92mTrain_score:" @@ -1096,7 +1097,7 @@ def grid_search_cv( ) ] if print_info: - print( + print_message( f"Model: {str(estimator.__class__).split('.')[-1][:-2]}; " f"Parameters: {config}; \033[91mTest_score: " f"{current_cv[keys[1]][cv]}\033[0m; \033[94mTime:" @@ -1104,7 +1105,7 @@ def grid_search_cv( ) except Exception as e: if skip_error and skip_error != "no_print": - print(e) + print_message(e) elif not skip_error: raise e if not data: @@ -1157,8 +1158,8 @@ def grid_search_cv( if print_info and ( "final_print" not in kwargs or kwargs["final_print"] != "no_print" ): - print("\033[1mGrid Search Selected Model\033[0m") - print( + print_message("\033[1mGrid Search Selected Model\033[0m") + print_message( f"{str(estimator.__class__).split('.')[-1][:-2]}; " f"Parameters: {result['parameters'][0]}; \033" f"[91mTest_score: {result['avg_score'][0]}\033[0m;" @@ -1177,8 +1178,8 @@ def grid_search_cv( if print_info and ( "final_print" not in kwargs or kwargs["final_print"] != "no_print" ): - print("\033[1mGrid Search Selected Model\033[0m") - print( + print_message("\033[1mGrid Search Selected Model\033[0m") + print_message( f"{str(estimator.__class__).split('.')[-1][:-2]}; " f"Parameters: {result['parameters'][0]}; \033[91mTest_score:" f" {result['avg_score'][0]}\033[0m; \033[94mTime:" @@ -1671,8 +1672,8 @@ def bayesian_search_cv( RFmodel_params, param_grid = format_type(RFmodel_params, param_grid, dtype=dict) X = format_type(X, dtype=list) if print_info: - print(f"\033[1m\033[4mStarting Bayesian Search\033[0m\033[0m\n") - print( + print_message(f"\033[1m\033[4mStarting Bayesian Search\033[0m\033[0m\n") + print_message( f"\033[1m\033[4mStep 1 - Computing Random Models" " using Grid Search\033[0m\033[0m\n" ) @@ -1724,7 +1725,7 @@ def bayesian_search_cv( drop(relation, method="table") _executeSQL(f"CREATE TABLE {relation} AS {result}", print_time_sql=False) if print_info: - print( + print_message( f"\033[1m\033[4mStep 2 - Fitting the RF model with " "the hyperparameters data\033[0m\033[0m\n" ) @@ -1790,7 +1791,7 @@ def bayesian_search_cv( param_tmp_grid[elem] = result[elem][i] new_param_grid += [param_tmp_grid] if print_info: - print( + print_message( f"\033[1m\033[4mStep 3 - Computing Most Probable Good " "Models using Grid Search\033[0m\033[0m\n" ) @@ -1820,8 +1821,8 @@ def bayesian_search_cv( result.values[elem] = [item[idx] for item in data] hyper_param_estimator.drop() if print_info: - print("\033[1mBayesian Search Selected Model\033[0m") - print( + print_message("\033[1mBayesian Search Selected Model\033[0m") + print_message( f"Parameters: {result['parameters'][0]}; \033[91mTest_score:" f" {result['avg_score'][0]}\033[0m; \033[92mTrain_score: " f"{result['avg_train_score'][0]}\033[0m; \033[94mTime: " diff --git a/verticapy/machine_learning/model_selection/kmeans.py b/verticapy/machine_learning/model_selection/kmeans.py index bd9b28dde..3276868bc 100755 --- a/verticapy/machine_learning/model_selection/kmeans.py +++ b/verticapy/machine_learning/model_selection/kmeans.py @@ -23,6 +23,7 @@ import verticapy._config.config as conf from verticapy._typing import PlottingObject, SQLColumns, SQLRelation +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._gen import gen_tmp_name from verticapy._utils._sql._format import format_type, quote_ident, schema_relation @@ -291,7 +292,7 @@ def best_k( if score > elbow_score_stop: return i model.drop() - print( + print_message( f"\u26A0 The K was not found. The last K (= {i}) " f"is returned with an elbow score of {score}" ) diff --git a/verticapy/machine_learning/model_selection/statistical_tests/ols.py b/verticapy/machine_learning/model_selection/statistical_tests/ols.py index bc621b859..7c3d51084 100755 --- a/verticapy/machine_learning/model_selection/statistical_tests/ols.py +++ b/verticapy/machine_learning/model_selection/statistical_tests/ols.py @@ -23,6 +23,7 @@ import verticapy._config.config as conf from verticapy._typing import NoneType, SQLColumns, SQLRelation +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type from verticapy._utils._gen import gen_tmp_name @@ -168,7 +169,7 @@ def het_breuschpagan( .. ipython:: python - print(lm_statistic, lm_pvalue, f_statistic, f_pvalue) + print_message(lm_statistic, lm_pvalue, f_statistic, f_pvalue) As the noise was not heteroscedestic, we got higher p_value scores and lower statistics score. @@ -278,7 +279,7 @@ def het_breuschpagan( .. ipython:: python - print(lm_statistic, lm_pvalue, f_statistic, f_pvalue) + print_message(lm_statistic, lm_pvalue, f_statistic, f_pvalue) .. note:: @@ -440,7 +441,7 @@ def het_goldfeldquandt( .. ipython:: python - print(statistic, pvalue) + print_message(statistic, pvalue) As the noise was not heteroscedestic, we got higher p_value scores and lower statistics score. @@ -527,7 +528,7 @@ def het_goldfeldquandt( .. ipython:: python - print(statistic, pvalue) + print_message(statistic, pvalue) .. note:: @@ -717,7 +718,7 @@ def het_white( .. ipython:: python - print(lm_statistic, lm_pvalue, f_statistic, f_pvalue) + print_message(lm_statistic, lm_pvalue, f_statistic, f_pvalue) As the noise was not heteroscedestic, we got higher p_value scores and lower statistics score. @@ -827,7 +828,7 @@ def het_white( .. ipython:: python - print(lm_statistic, lm_pvalue, f_statistic, f_pvalue) + print_message(lm_statistic, lm_pvalue, f_statistic, f_pvalue) .. note:: diff --git a/verticapy/machine_learning/model_selection/variables_selection.py b/verticapy/machine_learning/model_selection/variables_selection.py index 3a83250a2..2f268c258 100755 --- a/verticapy/machine_learning/model_selection/variables_selection.py +++ b/verticapy/machine_learning/model_selection/variables_selection.py @@ -31,6 +31,7 @@ SQLColumns, SQLRelation, ) +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type from verticapy._utils._sql._sys import _executeSQL @@ -488,7 +489,7 @@ def randomized_features_search_cv( ) ] if print_info: - print( + print_message( f"Model: {str(estimator.__class__).split('.')[-1][:-2]}; " f"Features: {config}; \033[91mTest_score: " f"{current_cv[0][keys[1]][cv]}\033[0m; \033[92mTrain_score:" @@ -506,7 +507,7 @@ def randomized_features_search_cv( ) ] if print_info: - print( + print_message( f"Model: {str(estimator.__class__).split('.')[-1][:-2]};" f" Features: {config}; \033[91mTest_score: " f"{current_cv[keys[1]][cv]}\033[0m; \033[94mTime:" @@ -514,7 +515,7 @@ def randomized_features_search_cv( ) except Exception as e: if skip_error and skip_error != "no_print": - print(e) + print_message(e) elif not skip_error: raise e if not data: @@ -567,8 +568,8 @@ def randomized_features_search_cv( if print_info and ( "final_print" not in kwargs or kwargs["final_print"] != "no_print" ): - print("\033[1mRandomized Features Search Selected Model\033[0m") - print( + print_message("\033[1mRandomized Features Search Selected Model\033[0m") + print_message( f"{str(estimator.__class__).split('.')[-1][:-2]}; Features:" f" {res['features'][0]}; \033[91mTest_score: " f"{res['avg_score'][0]}\033[0m; \033[92mTrain_score: " @@ -587,8 +588,8 @@ def randomized_features_search_cv( if print_info and ( "final_print" not in kwargs or kwargs["final_print"] != "no_print" ): - print("\033[1mRandomized Features Search Selected Model\033[0m") - print( + print_message("\033[1mRandomized Features Search Selected Model\033[0m") + print_message( f"{str(estimator.__class__).split('.')[-1][:-2]}; Features:" f" {res['features'][0]}; \033[91mTest_score: " f"{res['avg_score'][0]}\033[0m; \033[94mTime: " @@ -809,7 +810,7 @@ def stepwise( if direction == "backward": X.reverse() if print_info: - print("\033[1m\033[4mStarting Stepwise\033[0m\033[0m") + print_message("\033[1m\033[4mStarting Stepwise\033[0m\033[0m") if conf.get_option("tqdm") and print_info: loop = tqdm(range(len(X))) else: @@ -828,7 +829,7 @@ def stepwise( X_current = copy.deepcopy(X) for idx in loop: if print_info and idx == 0: - print( + print_message( f"\033[1m[Model 0]\033[0m \033[92m{criterion}: " f"{current_score}\033[0m; Variables: {X_current}" ) @@ -854,7 +855,7 @@ def stepwise( current_score = test_score X_current.remove(X[idx]) if print_info: - print( + print_message( f"\033[1m[Model {model_id}]\033[0m \033[92m{criterion}: " f"{test_score}\033[0m; \033[91m(-) Variable: {X[idx]}\033[0m" ) @@ -868,7 +869,7 @@ def stepwise( X_current = [] for idx in loop: if print_info and idx == 0: - print( + print_message( f"\033[1m[Model 0]\033[0m \033[92m{criterion}: " f"{current_score}\033[0m; Variables: {X_current}" ) @@ -890,7 +891,7 @@ def stepwise( current_score = test_score X_current += [X[idx]] if print_info: - print( + print_message( f"\033[1m[Model {model_id}]\033[0m \033[92m{criterion}:" f" {test_score}\033[0m; \033[91m(+) Variable: {X[idx]}\033[0m" ) @@ -899,8 +900,8 @@ def stepwise( res += [(X_test, test_score, sign, X[idx], idx + 1, score_diff)] current_step += 1 if print_info: - print(f"\033[1m\033[4mSelected Model\033[0m\033[0m\n") - print( + print_message(f"\033[1m\033[4mSelected Model\033[0m\033[0m\n") + print_message( f"\033[1m[Model {model_id}]\033[0m \033[92m{criterion}:" f" {current_score}\033[0m; Variables: {X_current}" ) diff --git a/verticapy/machine_learning/vertica/automl/clustering.py b/verticapy/machine_learning/vertica/automl/clustering.py index fe04b57d4..ff9f6c017 100755 --- a/verticapy/machine_learning/vertica/automl/clustering.py +++ b/verticapy/machine_learning/vertica/automl/clustering.py @@ -20,6 +20,7 @@ import verticapy._config.config as conf from verticapy._typing import ArrayLike, SQLColumns, SQLRelation +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy.machine_learning.model_selection import best_k @@ -175,7 +176,7 @@ def fit( else: self._is_already_stored(raise_error=True) if self.parameters["print_info"]: - print(f"\033[1m\033[4mStarting AutoClustering\033[0m\033[0m\n") + print_message(f"\033[1m\033[4mStarting AutoClustering\033[0m\033[0m\n") if self.parameters["preprocess_data"]: model_preprocess = AutoDataPrep(**self.parameters["preprocess_dict"]) model_preprocess.fit(input_relation, X=X) @@ -186,7 +187,7 @@ def fit( self.preprocess_ = None if not self.parameters["n_cluster"]: if self.parameters["print_info"]: - print( + print_message( f"\033[1m\033[4mFinding a suitable number of clusters\033[0m\033[0m\n" ) self.parameters["n_cluster"] = best_k( @@ -202,7 +203,7 @@ def fit( tqdm=self.parameters["print_info"], ) if self.parameters["print_info"]: - print(f"\033[1m\033[4mBuilding the Final Model\033[0m\033[0m\n") + print_message(f"\033[1m\033[4mBuilding the Final Model\033[0m\033[0m\n") if conf.get_option("tqdm") and self.parameters["print_info"]: loop = tqdm(range(1)) else: diff --git a/verticapy/machine_learning/vertica/automl/supervised.py b/verticapy/machine_learning/vertica/automl/supervised.py index 32d323e86..6e8850927 100755 --- a/verticapy/machine_learning/vertica/automl/supervised.py +++ b/verticapy/machine_learning/vertica/automl/supervised.py @@ -28,6 +28,7 @@ SQLColumns, ) from verticapy._utils._gen import gen_tmp_name +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type, schema_relation from verticapy._utils._sql._vertica_version import vertica_version @@ -544,14 +545,14 @@ def fit( else: self.preprocess_ = None if self.parameters["print_info"]: - print(f"\033[1m\033[4mStarting AutoML\033[0m\033[0m\n") + print_message(f"\033[1m\033[4mStarting AutoML\033[0m\033[0m\n") if conf.get_option("tqdm") and self.parameters["print_info"]: loop = tqdm(self.parameters["estimator"]) else: loop = self.parameters["estimator"] for elem in loop: if self.parameters["print_info"]: - print( + print_message( f"\n\033[1m\033[4mTesting Model - {str(elem.__class__).split('.')[-1][:-2]}\033[0m\033[0m\n" ) param_grid = gen_params_grid( @@ -639,8 +640,8 @@ def fit( "Error: 'AutoML' failed to converge. Please retry fitting the estimator." ) if self.parameters["print_info"]: - print(f"\033[1m\033[4mFinal Model\033[0m\033[0m\n") - print( + print_message(f"\033[1m\033[4mFinal Model\033[0m\033[0m\n") + print_message( f"{result['model_type'][0]}; Best_Parameters: {result['parameters'][0]}; \033[91mBest_Test_score: {result['avg_score'][0]}\033[0m; \033[92mTrain_score: {result['avg_train_score'][0]}\033[0m; \033[94mTime: {result['avg_time'][0]}\033[0m;\n\n" ) best_model = result["model_class"][0](self.model_name) diff --git a/verticapy/machine_learning/vertica/base.py b/verticapy/machine_learning/vertica/base.py index 179509a33..46366cbc8 100755 --- a/verticapy/machine_learning/vertica/base.py +++ b/verticapy/machine_learning/vertica/base.py @@ -16,7 +16,6 @@ """ import copy -import warnings from abc import abstractmethod from typing import Any, Callable, Literal, Optional, Union, get_type_hints import numpy as np @@ -35,6 +34,7 @@ SQLExpression, ) from verticapy._utils._gen import gen_name, gen_tmp_name +from verticapy._utils._print import print_message from verticapy._utils._sql._format import ( clean_query, format_type, @@ -1194,7 +1194,7 @@ def set_params(self, parameters: Optional[dict] = None, **kwargs) -> None: warning_message = ( f"parameter 'parameters' got an unexpected keyword argument '{p}'" ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") new_parameters[p] = parameters[p] self.__init__(name=self.model_name, **new_parameters) @@ -2428,7 +2428,7 @@ def fit( if return_report: return report if conf.get_option("print_info"): - print(report) + print_message(report) return None @@ -7996,5 +7996,5 @@ def fit( if return_report: return report if conf.get_option("print_info"): - print(report) + print_message(report) return None diff --git a/verticapy/machine_learning/vertica/neighbors.py b/verticapy/machine_learning/vertica/neighbors.py index 826bd2821..2e73cff3b 100755 --- a/verticapy/machine_learning/vertica/neighbors.py +++ b/verticapy/machine_learning/vertica/neighbors.py @@ -15,7 +15,6 @@ permissions and limitations under the License. """ import itertools -import warnings from typing import Literal, Optional import numpy as np @@ -31,6 +30,7 @@ SQLRelation, ) from verticapy._utils._gen import gen_name, gen_tmp_name +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import ( clean_query, @@ -2340,7 +2340,7 @@ def _density_compute( f"Wrong xlim for the vDataColumn {column}.\n" "The max and the min will be used instead." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") x_min, x_max = vdf.agg( func=["min", "max"], columns=[column] ).transpose()[column] diff --git a/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py b/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py index 2e7b0ef9d..690404d47 100644 --- a/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py +++ b/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py @@ -13,12 +13,17 @@ # To see how to use this script, run it without arguments. ########################################################################################### +import numpy as np +import json +import os +import sys + import tensorflow as tf from tensorflow.python.framework.convert_to_constants import ( # pylint: disable=no-name-in-module convert_variables_to_constants_v2, ) -import numpy as np -import json, os, sys + +from verticapy._utils._print import print_message os.environ["TF_CPP_MIN_LOG_LEVEL"] = "1" # suppress some TF noise @@ -40,13 +45,13 @@ def get_str_from_dtype(dtype, is_input, idx): if dtype in dtype_to_string: dtype_str = dtype_to_string[dtype] else: - print( + print_message( "Only floats, doubles, and signed ints are currently supported as model inputs/outputs in Vertica, please modify your model." ) sys.exit() in_or_out = "Input" if is_input else "Output" - print(in_or_out, str(idx), "is of type:", dtype_str) + print_message(in_or_out, str(idx), "is of type:", dtype_str) return dtype_str @@ -61,7 +66,7 @@ def freeze_model(model, save_dir, column_type): # Convert Keras model to ConcreteFunction full_model = tf.function(lambda x: model(x)) - print("Model Input:", model.input) + print_message("Model Input:", model.input) if isinstance(model.input, list): no_of_inputs = len(model.input) @@ -105,8 +110,8 @@ def freeze_model(model, save_dir, column_type): inputs = [] col_start = 0 for input_idx, inp in enumerate(frozen_func.inputs): - # print(inp.op.name) - # print(inp.get_shape()) + # print_message(inp.op.name) + # print_message(inp.get_shape()) input_dims = [1 if e is None else e for e in list(inp.get_shape())] dtype = get_str_from_dtype(inp.dtype, True, input_idx) inputs.append( @@ -127,8 +132,8 @@ def freeze_model(model, save_dir, column_type): outputs = [] col_start = 0 for output_idx, output in enumerate(frozen_func.outputs): - # print(output.op.name) - # print(output.get_shape()) + # print_message(output.op.name) + # print_message(output.get_shape()) output_dims = [1 if e is None else e for e in list(output.get_shape())] dtype = get_str_from_dtype(output.dtype, False, output_idx) outputs.append( @@ -188,7 +193,7 @@ def freeze_model(model, save_dir, column_type): save_desc_file(model_info, frozen_out_path, tf_model_desc_file) else: - print("Unrecognized column type flag") + print_message("Unrecognized column type flag") sys.exit() @@ -201,7 +206,7 @@ def freeze_model_from_file( def save_graph(frozen_func, frozen_out_path, frozen_graph_file): - print("Saving frozen model to: " + os.path.join(frozen_out_path, frozen_graph_file)) + print_message("Saving frozen model to: " + os.path.join(frozen_out_path, frozen_graph_file)) tf.io.write_graph( graph_or_graph_def=frozen_func.graph, logdir=frozen_out_path, @@ -211,7 +216,7 @@ def save_graph(frozen_func, frozen_out_path, frozen_graph_file): def save_desc_file(model_info, frozen_out_path, tf_model_desc_file): - print( + print_message( "Saving model description file to: " + os.path.join(frozen_out_path, tf_model_desc_file) ) @@ -241,17 +246,17 @@ def gen_tensor_list(tensors): if __name__ == "__main__": if len(sys.argv) < 2 or len(sys.argv) > 4 or sys.argv[1] in ["-h", "--help"]: - print("There are three arguments to the script:") - print("1. Path to your saved model directory") - print( + print_message("There are three arguments to the script:") + print_message("1. Path to your saved model directory") + print_message( "2. (Optional) name of the folder to save the frozen model (default: frozen_tfmodel)" ) - print( + print_message( "3. (Optional) Input/output Vertica column type in prediction (0 (default): primitive; 1: complex)" ) - print(" Use primitive if you want one value stored in each row/column cell.") - print(" Use complex if you want to store the data in Vertica arrays.") - print( + print_message(" Use primitive if you want one value stored in each row/column cell.") + print_message(" Use complex if you want to store the data in Vertica arrays.") + print_message( "Example call: ./freeze_tf_model.py path/to/saved/model my_frozen_model 0" ) sys.exit() @@ -265,4 +270,4 @@ def gen_tensor_list(tensors): elif len(sys.argv) == 4: freeze_model_from_file(str(sys.argv[1]), str(sys.argv[2]), str(sys.argv[3])) else: - print("Invalid number of arguments.") # unreachable, just here for completeness + print_message("Invalid number of arguments.") # unreachable, just here for completeness diff --git a/verticapy/machine_learning/vertica/tsa/base.py b/verticapy/machine_learning/vertica/tsa/base.py index 4d8485be9..9ea76a39c 100755 --- a/verticapy/machine_learning/vertica/tsa/base.py +++ b/verticapy/machine_learning/vertica/tsa/base.py @@ -30,6 +30,7 @@ SQLRelation, ) from verticapy._utils._gen import gen_tmp_name +from verticapy._utils._print import print_message from verticapy._utils._sql._format import ( clean_query, format_type, @@ -331,7 +332,7 @@ def fit( if return_report: return report if conf.get_option("print_info"): - print(report) + print_message(report) else: self._compute_attributes() return None diff --git a/verticapy/machine_learning/vertica/tsa/ensemble.py b/verticapy/machine_learning/vertica/tsa/ensemble.py index f6197c1fb..f29da9412 100755 --- a/verticapy/machine_learning/vertica/tsa/ensemble.py +++ b/verticapy/machine_learning/vertica/tsa/ensemble.py @@ -20,6 +20,7 @@ import verticapy._config.config as conf from verticapy._typing import NoneType, PlottingObject, SQLColumns, SQLRelation +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import extract_subquery, quote_ident, schema_relation from verticapy._utils._sql._sys import _executeSQL @@ -376,7 +377,7 @@ def fit( if return_report: return report if conf.get_option("print_info"): - print(report) + print_message(report) return None # I/O Methods. diff --git a/verticapy/mlops/model_tracking/base.py b/verticapy/mlops/model_tracking/base.py index 577022f5c..a9f95c269 100644 --- a/verticapy/mlops/model_tracking/base.py +++ b/verticapy/mlops/model_tracking/base.py @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. """ -import warnings import numpy as np import uuid from typing import Literal @@ -32,6 +31,7 @@ from verticapy.sql.drop import drop from verticapy.plotting._utils import PlottingUtils from verticapy._typing import PlottingObject +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._sys import _executeSQL @@ -206,7 +206,7 @@ def __init__( "The experiment will not be backed up in the database " "when experiment_table is not specified." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") if self.experiment_type == "clustering" or ( self.experiment_type == "auto" diff --git a/verticapy/performance/vertica/collection/collection_tables.py b/verticapy/performance/vertica/collection/collection_tables.py index 93eb19c5d..38b761472 100644 --- a/verticapy/performance/vertica/collection/collection_tables.py +++ b/verticapy/performance/vertica/collection/collection_tables.py @@ -23,6 +23,7 @@ import pandas as pd +from verticapy._utils._print import print_message from verticapy.core.parsers.pandas import read_pandas from verticapy.core.vdataframe import vDataFrame @@ -130,7 +131,7 @@ class TableMetadata: .. code-block:: python - print(f"JSON obj = {tmd.to_json()}") + print_message(f"JSON obj = {tmd.to_json()}") The output will be: @@ -188,7 +189,7 @@ def __init__(self, file_name: Path, table_type: AllTableTypes, exported_rows: in .. code-block:: python - print(f"JSON obj = {tmd.to_json()}") + print_message(f"JSON obj = {tmd.to_json()}") The output will be: @@ -251,7 +252,7 @@ def to_json(self) -> str: .. code-block:: python - print(f"JSON obj = {tmd.to_json()}") + print_message(f"JSON obj = {tmd.to_json()}") The output will be: @@ -319,7 +320,7 @@ class ExportMetadata: .. code-block:: python - print(f"JSON obj = {exp_md.to_json()}") + print_message(f"JSON obj = {exp_md.to_json()}") The output will be: @@ -389,7 +390,7 @@ def __init__( .. code-block:: python - print(f"JSON obj = {exp_md.to_json()}") + print_message(f"JSON obj = {exp_md.to_json()}") The output will be: @@ -464,7 +465,7 @@ def to_json(self) -> str: .. code-block:: python - print(f"JSON obj = {exp_md.to_json()}") + print_message(f"JSON obj = {exp_md.to_json()}") The output will be: @@ -538,7 +539,7 @@ def write_to_file(self) -> None: exp_md.write_to_file() with open("export_meta.json", "r") as readf: - print(f"JSON obj = {readf.read()}") + print_message(f"JSON obj = {readf.read()}") The output will be: diff --git a/verticapy/performance/vertica/collection/profile_export.py b/verticapy/performance/vertica/collection/profile_export.py index db4f5ba06..0bb3ff99b 100644 --- a/verticapy/performance/vertica/collection/profile_export.py +++ b/verticapy/performance/vertica/collection/profile_export.py @@ -24,6 +24,7 @@ import pandas as pd +from verticapy._utils._print import print_message from verticapy._utils._sql._sys import _executeSQL from verticapy.core.vdataframe import vDataFrame from verticapy.core.parsers.pandas import read_pandas @@ -69,7 +70,7 @@ class ProfileExportError(Exception): try: exporter.export() except ProfileExportError as err: - print(f"Observed a ProfileExport error") + print_message(f"Observed a ProfileExport error") The output will be: @@ -157,7 +158,7 @@ class ProfileExport: tfile = tarfile.open("query_requests_example_001.tar") for f in tfile.getnames(): - print(f"Tarball contains path: {f}") + print_message(f"Tarball contains path: {f}") The output will be: @@ -220,7 +221,7 @@ def __init__( .. code-block:: python - print(f"Target schema is {exporter.target_schema}\n" + print_message(f"Target schema is {exporter.target_schema}\n" f"Key is {exporter.key}\n" f"filename is {exporter.filename}") @@ -276,7 +277,7 @@ def tmp_path(self) -> Path: .. code-block:: python - print(f"Temp path = {exporter.tmp_path}") + print_message(f"Temp path = {exporter.tmp_path}") The output will be the current working directory. For this example, let's assume the current working directory is ``/home/u1``. @@ -323,7 +324,7 @@ def tmp_path(self, val: os.PathLike) -> None: .. code-block:: python - print(f"Temp path = {exporter.tmp_path}") + print_message(f"Temp path = {exporter.tmp_path}") The output will be: @@ -414,7 +415,7 @@ def export(self) -> None: tfile = tarfile.open("query_requests_example_001.tar") for f in tfile.getnames(): - print(f"Tarball contains path: {f}") + print_message(f"Tarball contains path: {f}") The output will be: diff --git a/verticapy/performance/vertica/collection/profile_import.py b/verticapy/performance/vertica/collection/profile_import.py index 8f0fa7c2d..37a4cb9e9 100644 --- a/verticapy/performance/vertica/collection/profile_import.py +++ b/verticapy/performance/vertica/collection/profile_import.py @@ -24,6 +24,7 @@ import pandas as pd +from verticapy._utils._print import print_message from verticapy._utils._sql._sys import _executeSQL from verticapy.core.vdataframe import vDataFrame from verticapy.core.parsers.pandas import read_pandas @@ -254,18 +255,18 @@ def _unpack_bundle(self) -> Path: self.tarfile_obj = tarfile.open(self.filename, "r") names = "\n".join(self.tarfile_obj.getnames()) - print(f"Files in the archive: {names}") + print_message(f"Files in the archive: {names}") current_datetime = datetime.datetime.now() timestamp_suffix = current_datetime.strftime("%Y-%m-%d_%H-%M-%S_%f") tmp_dir = self.tmp_path / Path(f"profile_import_run_{timestamp_suffix}") - print(f"Creating temporary directory: {tmp_dir}") + print_message(f"Creating temporary directory: {tmp_dir}") tmp_dir.mkdir() self.tarfile_obj.extractall(tmp_dir) - print(f"Extracted files: {[x for x in tmp_dir.iterdir()]}") + print_message(f"Extracted files: {[x for x in tmp_dir.iterdir()]}") return tmp_dir diff --git a/verticapy/performance/vertica/qprof.py b/verticapy/performance/vertica/qprof.py index 39d61fafa..5b49fb59d 100755 --- a/verticapy/performance/vertica/qprof.py +++ b/verticapy/performance/vertica/qprof.py @@ -20,7 +20,6 @@ import re from typing import Any, Callable, Literal, Optional, Union, TYPE_CHECKING import uuid -import warnings from tqdm.auto import tqdm @@ -31,6 +30,7 @@ import verticapy._config.config as conf from verticapy._typing import NoneType, PlottingObject, SQLExpression from verticapy._utils._parsers import parse_explain_graphviz +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import clean_query, format_query, format_type from verticapy._utils._sql._sys import _executeSQL @@ -425,13 +425,13 @@ class QueryProfiler: tid = qprof.transaction_id sid = qprof.statement_id - print(f"tid={tid};sid={sid}") + print_message(f"tid={tid};sid={sid}") Or simply: .. ipython:: python - print(qprof.transactions) + print_message(qprof.transactions) To avoid recomputing a query, you can also directly use its statement @@ -1070,7 +1070,7 @@ def __init__( "supported. A new key will be then generated: " f"{self.key_id}" ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") else: if isinstance(key_id, int): self.key_id = str(key_id) @@ -1210,7 +1210,7 @@ def __init__( "\nIt might be still running. This transaction" " will be skipped." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") session_params_non_default += [ self._get_current_session_params_non_default() ] @@ -1255,7 +1255,7 @@ def __init__( # SETTING THE requests AND queries durations. if conf.get_option("print_info") and print_info: - print("Setting the requests and queries durations...") + print_message("Setting the requests and queries durations...") self._set_request_qd() # WARNING MESSAGES. @@ -1496,7 +1496,7 @@ def _create_copy_v_table(self, print_info: bool = True) -> None: v_config_table_list = self._v_config_table_list() loop = v_temp_table_dict.items() if conf.get_option("print_info") and print_info: - print("Searching the performance tables...") + print_message("Searching the performance tables...") if conf.get_option("tqdm") and print_info: loop = tqdm(loop, total=len(loop)) idx = 0 @@ -1557,12 +1557,12 @@ def _create_copy_v_table(self, print_info: bool = True) -> None: ] except: if conf.get_option("print_info") and idx == 0: - print("Some tables seem to not exist...") - print("Creating a copy of the performance tables...\n") - print( + print_message("Some tables seem to not exist...") + print_message("Creating a copy of the performance tables...\n") + print_message( f"The key used to build up the tables is: {self.key_id}\n" ) - print("You can access the key by using the 'key_id' attribute.") + print_message("You can access the key by using the 'key_id' attribute.") exists = False idx += 1 @@ -1577,7 +1577,7 @@ def _create_copy_v_table(self, print_info: bool = True) -> None: if not (exists) or (self.overwrite): if conf.get_option("print_info"): - print( + print_message( f"Copy of {schema}.{table} created in {new_schema}.{new_table}" ) try: @@ -1599,7 +1599,7 @@ def _create_copy_v_table(self, print_info: bool = True) -> None: " to skip the table creation and to use the existing " "ones.\n\nError Details:\n" + str(e) ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") self.target_tables = target_tables def _insert_copy_v_table( @@ -1639,7 +1639,7 @@ def _insert_copy_v_table( v_config_table_list = self._v_config_table_list() loop = v_temp_table_dict.items() if conf.get_option("print_info"): - print("Inserting the new transactions...") + print_message("Inserting the new transactions...") if conf.get_option("tqdm"): loop = tqdm(loop, total=len(loop)) idx = 0 @@ -1671,7 +1671,7 @@ def _insert_copy_v_table( f"{transactions} in the relation {new_schema}.{new_table}.\n" "\n\nError Details:\n" + str(e) ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") self.__init__( key_id=self.key_id, target_schema=self.target_schema, @@ -1688,7 +1688,7 @@ def _insert_copy_v_table( f"{transactions}\n" "Are you sure that they exist?" ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") def _check_v_table( self, iterchecks: bool = True, ignore_operators_check: bool = True @@ -1723,7 +1723,7 @@ def _check_v_table( if conf.get_option("tqdm"): loop = tqdm(loop, total=len(loop)) if conf.get_option("print_info"): - print("Checking all the tables consistency iteratively...") + print_message("Checking all the tables consistency iteratively...") for tr_id, st_id in loop: for table_name in tables: if table_name not in config_table: @@ -1770,7 +1770,7 @@ def _check_v_table( jointables += [current_table] relations += [f"{sc}.{tb}"] if conf.get_option("print_info"): - print("Checking all the tables consistency using a single SQL query...") + print_message("Checking all the tables consistency using a single SQL query...") query = ( "SELECT " + ", ".join(select) @@ -1810,7 +1810,7 @@ def _check_v_table( table_name_list = list(self._v_table_dict()) n = len(self.tables_dtypes) if conf.get_option("print_info"): - print("Checking all the tables data types...") + print_message("Checking all the tables data types...") for i in range(n): table_name = table_name_list[i] table_1 = self.v_tables_dtypes[i] @@ -1868,7 +1868,7 @@ def _check_v_table( "removed, especially if you are directly working on the " "performance tables." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") def _set_request_qd(self): """ @@ -3217,7 +3217,7 @@ def get_qplan( ) res = "\n".join([l[3] for l in path]) if print_plan: - print(res) + print_message(res) return res vdf = vDataFrame(query).sort(["stmtid", "path_id", "path_line_index"]) return vdf @@ -5057,7 +5057,7 @@ def export_profile(self, filename: os.PathLike) -> None: tfile = tarfile.open("query_requests_example_001.tar") for f in tfile.getnames(): - print(f"Tarball contains path: {f}") + print_message(f"Tarball contains path: {f}") The output will be: @@ -5186,7 +5186,7 @@ def import_profile( .. code-block:: python - print(f"First query duration was {qprof_imported.get_qduration()} seconds") + print_message(f"First query duration was {qprof_imported.get_qduration()} seconds") Let's assume the query had a duration of 3.14 seconds. The output will be: diff --git a/verticapy/pipeline/_transform.py b/verticapy/pipeline/_transform.py index 4e5ef95c2..35574e49d 100644 --- a/verticapy/pipeline/_transform.py +++ b/verticapy/pipeline/_transform.py @@ -20,6 +20,7 @@ """ from queue import Queue +from verticapy._utils._print import print_message from verticapy.core.vdataframe.base import vDataFrame @@ -137,7 +138,7 @@ def transformation(transform: dict, table: str) -> vDataFrame: transformed_vdf = transformation(transform, table) # Display the transformed vDataFrame - print(transformed_vdf) + print_message(transformed_vdf) """ vdf = vDataFrame(table) column_queue = Queue() diff --git a/verticapy/pipeline/parser.py b/verticapy/pipeline/parser.py index 5f99c2c67..76565056f 100644 --- a/verticapy/pipeline/parser.py +++ b/verticapy/pipeline/parser.py @@ -25,6 +25,7 @@ import verticapy as vp +from verticapy._utils._print import print_message from verticapy._utils._sql._sys import _executeSQL from verticapy.datasets import ( @@ -168,7 +169,7 @@ def parse_yaml(pipeline: dict): TEST_SQL, TABLE_SQL = _validate.testing(test, MODEL, pipeline_name, COLS) META_SQL += TEST_SQL pbar.update() - print( + print_message( _executeSQL( f"SELECT * FROM {pipeline_name + '_METRIC_TABLE'};" ).fetchall() diff --git a/verticapy/plotting/_highcharts/scatter.py b/verticapy/plotting/_highcharts/scatter.py index a6514024f..713f8a8dc 100755 --- a/verticapy/plotting/_highcharts/scatter.py +++ b/verticapy/plotting/_highcharts/scatter.py @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. """ -import warnings from typing import Literal, Optional import numpy as np from verticapy._typing import HChart +from verticapy._utils._print import print_message from verticapy.plotting._highcharts.base import HighchartsBase @@ -122,7 +122,7 @@ def draw(self, chart: Optional[HChart] = None, **style_kwargs) -> HChart: has_cmap = self.layout["has_cmap"] if has_cmap: warning_message = f"The parameter {has_cmap} is not supported on the Highchart API. It is ignored." - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") chart, style_kwargs = self._get_chart(chart, style_kwargs=style_kwargs) chart.set_dict_options(self.init_style) chart.set_dict_options(style_kwargs) diff --git a/verticapy/plotting/_utils.py b/verticapy/plotting/_utils.py index 6c993fce0..8930e7ac5 100755 --- a/verticapy/plotting/_utils.py +++ b/verticapy/plotting/_utils.py @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. """ -import warnings from typing import Literal, Optional from matplotlib.axes import Axes @@ -23,6 +22,7 @@ from vertica_highcharts import Highchart, Highstock import verticapy._config.config as conf +from verticapy._utils._print import print_message from verticapy._utils._sql._format import format_type from verticapy._typing import PlottingObject @@ -103,7 +103,7 @@ def get_plotting_lib( "function.\nThe following example sets matplotlib as graphical library:\n" "import verticapy\nverticapy.set_option('plotting_lib', 'matplotlib')" ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") if lib == "plotly": vpy_plt = vpy_plotly_plt kwargs = {"fig": chart, **plotly_kwargs, **style_kwargs} diff --git a/verticapy/plotting/base.py b/verticapy/plotting/base.py index be43f36cf..244c22356 100755 --- a/verticapy/plotting/base.py +++ b/verticapy/plotting/base.py @@ -17,7 +17,6 @@ import copy import math import random -import warnings from typing import Callable, Literal, Optional, Union, TYPE_CHECKING import numpy as np @@ -35,6 +34,7 @@ SQLColumns, ) from verticapy._utils._object import create_new_vdf +from verticapy._utils._print import print_message from verticapy._utils._sql._cast import to_varchar from verticapy._utils._sql._format import clean_query, format_type, quote_ident from verticapy._utils._sql._sys import _executeSQL @@ -863,7 +863,7 @@ def _compute_hists_params( f"The Virtual Column {col} is not numerical." " Its histogram will not be drawn." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") if not columns_: raise ValueError("No quantitative feature to plot.") columns_, by = vdf.format_colnames(columns_, by) diff --git a/verticapy/sdk/vertica/udf/gen.py b/verticapy/sdk/vertica/udf/gen.py index cc9dea943..1769d4d18 100755 --- a/verticapy/sdk/vertica/udf/gen.py +++ b/verticapy/sdk/vertica/udf/gen.py @@ -17,6 +17,7 @@ import os from typing import Optional, Union +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type @@ -109,13 +110,13 @@ def generate_lib_udf( .. ipython:: python - print(udx_str) + print_message(udx_str) Print the SQL statements that install the function: .. ipython:: python - print("\\n".join(udx_sql)) + print_message("\\n".join(udx_sql)) .. note:: diff --git a/verticapy/sdk/vertica/udf/load.py b/verticapy/sdk/vertica/udf/load.py index 2a1524a42..5f718ed8e 100755 --- a/verticapy/sdk/vertica/udf/load.py +++ b/verticapy/sdk/vertica/udf/load.py @@ -15,9 +15,9 @@ permissions and limitations under the License. """ import os -import warnings from typing import Union +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy.sql.sys import _executeSQL, current_session, username @@ -140,7 +140,7 @@ def import_lib_udf( _executeSQL(query, title=f"UDF installation. [step {idx}]") return True except Exception as e: - warnings.warn(e, Warning) + print_message(e, "Warning") return False finally: os.remove(f"{directory}/{file_name}") diff --git a/verticapy/sql/dtypes.py b/verticapy/sql/dtypes.py index e3e6996ec..00f2f8cb5 100644 --- a/verticapy/sql/dtypes.py +++ b/verticapy/sql/dtypes.py @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. """ -import warnings import vertica_python from typing import Optional, Union @@ -22,6 +21,7 @@ import verticapy._config.config as conf from verticapy._utils._gen import gen_tmp_name +from verticapy._utils._print import print_message from verticapy._utils._sql._format import format_type, format_schema_table, quote_ident from verticapy._utils._sql._sys import _executeSQL from verticapy.connection import current_cursor @@ -194,7 +194,7 @@ def get_data_types( "As parameter 'table_name' is defined, " "parameter 'expression' is ignored." ) - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") if isinstance(current_cursor(), vertica_python.vertica.cursor.Cursor) and not ( table_name ): diff --git a/verticapy/sql/geo/index.py b/verticapy/sql/geo/index.py index 4581daa87..d1654931f 100755 --- a/verticapy/sql/geo/index.py +++ b/verticapy/sql/geo/index.py @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. """ -import warnings from typing import Optional, Union +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._sys import _executeSQL from verticapy._typing import SQLRelation @@ -455,7 +455,7 @@ def rename_index(source: str, dest: str, overwrite: bool = False) -> bool: ) except Exception as e: - warnings.warn(str(e), Warning) + print_message(str(e), "Warning") return False return True diff --git a/verticapy/sql/insert.py b/verticapy/sql/insert.py index 26721b796..ef4a4945f 100755 --- a/verticapy/sql/insert.py +++ b/verticapy/sql/insert.py @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. """ -import warnings from typing import Union, Optional import verticapy._config.config as conf +from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import ( clean_query, @@ -227,7 +227,7 @@ def insert_into( total_rows += 1 except Exception as e: warning_message = f"Line {i} was skipped.\n{e}" - warnings.warn(warning_message, Warning) + print_message(warning_message, "Warning") if genSQL: return sql else: From 44ade0966c9d8c38ce20488ad6000c461d8fb59d Mon Sep 17 00:00:00 2001 From: Badr Date: Wed, 2 Oct 2024 05:25:22 -0400 Subject: [PATCH 2/7] PART2 - multiple corrections --- verticapy/_config/validators.py | 29 +++++++++---------- verticapy/_utils/_display.py | 1 + verticapy/_utils/_inspect_statistics.py | 3 +- verticapy/_utils/_logo.py | 3 +- verticapy/_utils/_parsers.py | 6 ++-- verticapy/_utils/_print.py | 3 +- verticapy/_utils/_sql/_format.py | 22 +++++++------- verticapy/_utils/_sql/_merge.py | 3 +- verticapy/connection/oauth_manager.py | 2 +- verticapy/connection/write.py | 2 +- verticapy/core/parsers/all.py | 2 +- verticapy/core/parsers/csv.py | 6 ++-- verticapy/core/parsers/json.py | 4 ++- verticapy/core/parsers/shp.py | 4 ++- verticapy/core/tablesample/base.py | 4 +-- verticapy/core/vdataframe/_aggregate.py | 2 +- verticapy/core/vdataframe/_encoding.py | 4 +-- verticapy/core/vdataframe/_fill.py | 2 +- verticapy/core/vdataframe/_filter.py | 2 +- .../core/vdataframe/_machine_learning.py | 2 +- verticapy/core/vdataframe/_plotting.py | 2 +- verticapy/core/vdataframe/_scaler.py | 12 ++++---- verticapy/core/vdataframe/_sys.py | 8 ++--- verticapy/core/vdataframe/base.py | 2 +- verticapy/jupyter/extensions/chart_magic.py | 2 +- verticapy/jupyter/extensions/sql_magic.py | 8 ++--- .../model_selection/statistical_tests/ols.py | 13 ++++----- verticapy/machine_learning/vertica/base.py | 2 +- .../machine_learning/vertica/neighbors.py | 2 +- .../vertica/tensorflow/freeze_tf2_model.py | 12 ++++++-- verticapy/mlops/model_tracking/base.py | 2 +- .../vertica/collection/collection_tables.py | 15 +++++----- .../vertica/collection/profile_export.py | 14 ++++----- verticapy/performance/vertica/qprof.py | 28 ++++++++++-------- verticapy/pipeline/_transform.py | 3 +- verticapy/plotting/_highcharts/scatter.py | 2 +- verticapy/plotting/_utils.py | 2 +- verticapy/plotting/base.py | 2 +- verticapy/sdk/vertica/udf/gen.py | 5 ++-- verticapy/sdk/vertica/udf/load.py | 2 +- verticapy/sql/dtypes.py | 2 +- verticapy/sql/geo/index.py | 2 +- verticapy/sql/insert.py | 2 +- 43 files changed, 130 insertions(+), 120 deletions(-) diff --git a/verticapy/_config/validators.py b/verticapy/_config/validators.py index 275f5374f..415d82062 100755 --- a/verticapy/_config/validators.py +++ b/verticapy/_config/validators.py @@ -16,7 +16,6 @@ """ from typing import Any, Callable, Literal, Optional -from verticapy._utils._print import print_message from verticapy._typing import NoneType @@ -59,8 +58,8 @@ def bool_validator(val: bool) -> Literal[True]: try: bool_validator('Hello') except ValueError as e: - print_message('Error raised:') - print_message(e) + print('Error raised:') + print(e) .. seealso:: @@ -114,8 +113,8 @@ def in_validator(values: list) -> Callable[[Any], Literal[True]]: try: in_validator_ABC('D') except ValueError as e: - print_message('Error raised:') - print_message(e) + print('Error raised:') + print(e) .. seealso:: @@ -173,8 +172,8 @@ def optional_bool_validator(val: Optional[bool]) -> Literal[True]: try: optional_bool_validator('Hello') except ValueError as e: - print_message('Error raised:') - print_message(e) + print('Error raised:') + print(e) .. seealso:: @@ -228,8 +227,8 @@ def optional_positive_int_validator(val: Optional[int]) -> Literal[True]: try: optional_positive_int_validator(-3) except ValueError as e: - print_message('Error raised:') - print_message(e) + print('Error raised:') + print(e) .. seealso:: @@ -283,8 +282,8 @@ def optional_str_validator(val: Optional[str]) -> Literal[True]: try: optional_str_validator(7) except ValueError as e: - print_message('Error raised:') - print_message(e) + print('Error raised:') + print(e) .. seealso:: @@ -335,8 +334,8 @@ def str_validator(val: str) -> Literal[True]: try: str_validator(-1) except ValueError as e: - print_message('Error raised:') - print_message(e) + print('Error raised:') + print(e) .. seealso:: @@ -387,8 +386,8 @@ def st_positive_int_validator(val: int) -> Literal[True]: try: st_positive_int_validator(-1) except ValueError as e: - print_message('Error raised:') - print_message(e) + print('Error raised:') + print(e) .. seealso:: diff --git a/verticapy/_utils/_display.py b/verticapy/_utils/_display.py index ae129919a..a57231808 100755 --- a/verticapy/_utils/_display.py +++ b/verticapy/_utils/_display.py @@ -24,6 +24,7 @@ from verticapy._utils._sql._format import format_type from verticapy._utils._logo import verticapy_logo_html + def print_table( data_columns, is_finished: bool = True, diff --git a/verticapy/_utils/_inspect_statistics.py b/verticapy/_utils/_inspect_statistics.py index 7a059c617..1daf82a61 100644 --- a/verticapy/_utils/_inspect_statistics.py +++ b/verticapy/_utils/_inspect_statistics.py @@ -22,7 +22,6 @@ import verticapy as vp from verticapy._typing import PlottingObject, NoneType from verticapy._utils._object import create_new_vdf -from verticapy._utils._print import print_message if TYPE_CHECKING: from verticapy.core.vdataframe.base import vDataFrame @@ -241,7 +240,7 @@ def gen_rst_summary_table() -> str: from verticapy._utils._inspect_statistics import gen_rst_summary_table # Example. - print_message(gen_rst_summary_table()) + print(gen_rst_summary_table()) .. note:: diff --git a/verticapy/_utils/_logo.py b/verticapy/_utils/_logo.py index ccb1d45ee..2787fc805 100755 --- a/verticapy/_utils/_logo.py +++ b/verticapy/_utils/_logo.py @@ -15,6 +15,7 @@ permissions and limitations under the License. """ + def verticapy_logo_html(size: str = "50%") -> str: """ Generates the HTML code @@ -87,7 +88,7 @@ def verticapy_logo_str() -> str: logo = verticapy_logo_str() # printing the result - print_message(logo) + print(logo) .. note:: diff --git a/verticapy/_utils/_parsers.py b/verticapy/_utils/_parsers.py index bfc2edd1d..7d47a6009 100755 --- a/verticapy/_utils/_parsers.py +++ b/verticapy/_utils/_parsers.py @@ -104,7 +104,7 @@ def get_header_names( "to CSV while retaining its indexes.\nTip: Use " "index=False when exporting with pandas.DataFrame.to_csv." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") return list_strip(file_header) @@ -183,7 +183,7 @@ def get_first_record_as_list(path: str, sep: str, record_terminator: str) -> Lis # with a first line that looks like # col1,col2,col3 cols = get_first_record_as_list('test.csv', ',', '\\n') - print_message(cols) + print(cols) # Should print # ['col1', 'col2', 'col3'] @@ -223,7 +223,7 @@ def read_first_record(path: str, record_terminator: str) -> str: # col1,col2,col3; # 100,abc,3.14; r = read_first_record('test.csv', ',', ';') - print_message(r) + print(r) # Should print # 'col1,col2,col3;' """ diff --git a/verticapy/_utils/_print.py b/verticapy/_utils/_print.py index 39b4bcfb5..a4b210ba9 100644 --- a/verticapy/_utils/_print.py +++ b/verticapy/_utils/_print.py @@ -16,6 +16,7 @@ """ import warnings + def print_message(message: str, mtype: Literal["auto", "warning"] = "auto") -> None: """ Prints the input message or warning. @@ -26,4 +27,4 @@ def print_message(message: str, mtype: Literal["auto", "warning"] = "auto") -> N if mtype == "warning": warnings.warn(message, Warning) elif mtype == "auto": - print_message(message) \ No newline at end of file + print(message) diff --git a/verticapy/_utils/_sql/_format.py b/verticapy/_utils/_sql/_format.py index c98ec9f01..b48ed34ed 100755 --- a/verticapy/_utils/_sql/_format.py +++ b/verticapy/_utils/_sql/_format.py @@ -554,8 +554,8 @@ def _format_keys( sql, html_sql = _format_keys( SQL_KEYWORDS, sql, html_sql, KEYWORDS_TAG_L, KEYWORDS_TAG_R ) - print_message(sql) - print_message(html_sql) + print(sql) + print(html_sql) .. note:: @@ -748,7 +748,7 @@ def clean_query(query: SQLExpression) -> SQLExpression: sql += "subtable; -- simple query example" # Example. - print_message(clean_query(sql)) + print(clean_query(sql)) .. note:: @@ -803,7 +803,7 @@ def erase_comment(query: SQLExpression) -> SQLExpression: sql += "subtable; -- simple query example" # Example. - print_message(erase_comment(sql)) + print(erase_comment(sql)) .. note:: @@ -847,7 +847,7 @@ def erase_label(query: SQLExpression) -> SQLExpression: sql += "subtable; -- simple query example" # Example. - print_message(erase_label(sql)) + print(erase_label(sql)) .. note:: @@ -892,7 +892,7 @@ def extract_subquery(query: SQLExpression) -> SQLExpression: sql += "subtable -- simple query example) subtable2;" # Example. - print_message(extract_subquery(sql)) + print(extract_subquery(sql)) .. note:: @@ -941,7 +941,7 @@ def extract_and_rename_subquery(query: SQLExpression, alias: str) -> SQLExpressi sql += "subtable -- simple query example) subtable2;" # Example. - print_message( + print( extract_and_rename_subquery( sql, alias = 'new_alias', @@ -1252,7 +1252,7 @@ def indent_vpy_sql(query: SQLExpression) -> SQLExpression: sql += "subtable; -- simple query example" # Example. - print_message(indent_vpy_sql(sql)) + print(indent_vpy_sql(sql)) .. note:: @@ -1447,7 +1447,7 @@ def replace_label( sql += "subtable; -- simple query example" # Example. - print_message( + print( indent_vpy_sql( sql, new_label = 'label_test', @@ -1532,7 +1532,7 @@ def replace_vars_in_query(query: SQLExpression, locals_dict: dict) -> SQLExpress } # Example. - print_message(replace_vars_in_query(sql, locals_dict = vars)) + print(replace_vars_in_query(sql, locals_dict = vars)) .. note:: @@ -1574,7 +1574,7 @@ def replace_vars_in_query(query: SQLExpression, locals_dict: dict) -> SQLExpress warning_message = ( f"Failed to replace variables in the query.\nError: {e}" ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") fail = True if not fail: object_type = None diff --git a/verticapy/_utils/_sql/_merge.py b/verticapy/_utils/_sql/_merge.py index 7527e7f1a..52a985299 100755 --- a/verticapy/_utils/_sql/_merge.py +++ b/verticapy/_utils/_sql/_merge.py @@ -16,7 +16,6 @@ """ from typing import Optional -from verticapy._utils._print import print_message from verticapy._utils._sql._format import format_type, quote_ident @@ -566,7 +565,7 @@ def gen_coalesce(group_dict: dict) -> str: # Creating the dictionary. d = group_similar_names(names, skip_word = word) - print_message(d) + print(d) # Example gen_coalesce(d) diff --git a/verticapy/connection/oauth_manager.py b/verticapy/connection/oauth_manager.py index a00b27b4e..3c3dafe8c 100644 --- a/verticapy/connection/oauth_manager.py +++ b/verticapy/connection/oauth_manager.py @@ -65,7 +65,7 @@ def set_config(self, configs) -> None: for k, v in configs.items(): if k not in valid_keys: invalid_key = f"Unrecognized OAuth config property: {k}" - print_message(invalid_key, "Warning") + print_message(invalid_key, "warning") continue if v is None or v == "": # ignore empty value continue diff --git a/verticapy/connection/write.py b/verticapy/connection/write.py index 57963640a..5baca2c75 100755 --- a/verticapy/connection/write.py +++ b/verticapy/connection/write.py @@ -183,7 +183,7 @@ def delete_connection(name: str) -> bool: return True else: - print_message(f"The connection {name} does not exist.", "Warning") + print_message(f"The connection {name} does not exist.", "warning") return False diff --git a/verticapy/core/parsers/all.py b/verticapy/core/parsers/all.py index cf906e383..db83964d1 100755 --- a/verticapy/core/parsers/all.py +++ b/verticapy/core/parsers/all.py @@ -476,7 +476,7 @@ def read_file( extract_col_dt = extract_col_dt_from_query(result[0], col) if extract_col_dt is None: warning_message = f"The column '{col}' was not found.\nIt will be skipped." - print_message(warning_message, "Warning") + print_message(warning_message, "warning") else: column, ctype = extract_col_dt result[0] = result[0].replace( diff --git a/verticapy/core/parsers/csv.py b/verticapy/core/parsers/csv.py index 9dbfeb0a0..8634725dd 100755 --- a/verticapy/core/parsers/csv.py +++ b/verticapy/core/parsers/csv.py @@ -732,7 +732,7 @@ def read_csv( "Parameters 'header_names' and 'dtype' are both defined. " "Only 'dtype' will be used." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") basename = ".".join(path.split("/")[-1].split(".")[0:-1]) if gen_tmp_table_name and temporary_local_table and not table_name: table_name = gen_tmp_name(name=basename) @@ -942,7 +942,9 @@ def read_csv( and not temporary_local_table and conf.get_option("print_info") ): - print_message(f"The table {input_relation} has been successfully created.") + print_message( + f"The table {input_relation} has been successfully created." + ) return vDataFrame(table_name, schema=schema) diff --git a/verticapy/core/parsers/json.py b/verticapy/core/parsers/json.py index 404b7c308..676ef28fe 100755 --- a/verticapy/core/parsers/json.py +++ b/verticapy/core/parsers/json.py @@ -800,7 +800,9 @@ def read_json( title="Creating table.", ) if not temporary_local_table and conf.get_option("print_info"): - print_message(f"The table {input_relation} has been successfully created.") + print_message( + f"The table {input_relation} has been successfully created." + ) else: column_name_dtype = {} for elem in column_name: diff --git a/verticapy/core/parsers/shp.py b/verticapy/core/parsers/shp.py index ef33d3536..f31f534b7 100755 --- a/verticapy/core/parsers/shp.py +++ b/verticapy/core/parsers/shp.py @@ -126,5 +126,7 @@ def read_shp( title="Ingesting the data.", ) if conf.get_option("print_info"): - print_message(f'The table "{schema}"."{table_name}" has been successfully created.') + print_message( + f'The table "{schema}"."{table_name}" has been successfully created.' + ) return vDataFrame(table_name, schema=schema) diff --git a/verticapy/core/tablesample/base.py b/verticapy/core/tablesample/base.py index 4a3ca61e2..a35f5203f 100644 --- a/verticapy/core/tablesample/base.py +++ b/verticapy/core/tablesample/base.py @@ -139,7 +139,7 @@ class TableSample: tb.to_pandas() # Exporting to SQL. - print_message(tb.to_sql()) + print(tb.to_sql()) .. note:: @@ -1587,7 +1587,7 @@ def to_sql(self) -> str: .. ipython:: python - print_message(tb.to_sql()) + print(tb.to_sql()) .. seealso:: diff --git a/verticapy/core/vdataframe/_aggregate.py b/verticapy/core/vdataframe/_aggregate.py index 648d1dbb0..8f8c75275 100755 --- a/verticapy/core/vdataframe/_aggregate.py +++ b/verticapy/core/vdataframe/_aggregate.py @@ -1028,7 +1028,7 @@ def describe( "\nTo get statistical information about all different " "variables, please use the parameter method = 'categorical'." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") for column in columns: if column not in col_to_compute: values["index"] += [column.replace('"', "")] diff --git a/verticapy/core/vdataframe/_encoding.py b/verticapy/core/vdataframe/_encoding.py index 8be3ba38c..90830c4da 100755 --- a/verticapy/core/vdataframe/_encoding.py +++ b/verticapy/core/vdataframe/_encoding.py @@ -354,7 +354,7 @@ def one_hot_encode( "'max_cardinality' to solve this issue or use " "directly the vDataColumn one_hot_encode method." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") return self get_dummies = one_hot_encode @@ -1495,7 +1495,7 @@ def label_encode(self) -> "vDataFrame": warning_message = ( "label_encode is only available for categorical variables." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") else: distinct_elements = self.distinct() expr = ["DECODE({}"] diff --git a/verticapy/core/vdataframe/_fill.py b/verticapy/core/vdataframe/_fill.py index c8bee551c..ce429d452 100755 --- a/verticapy/core/vdataframe/_fill.py +++ b/verticapy/core/vdataframe/_fill.py @@ -881,7 +881,7 @@ def fillna( f"The vDataColumn {self} has no mode " "(only missing values).\nNothing was filled." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") return self._parent if isinstance(val, str): val = val.replace("'", "''") diff --git a/verticapy/core/vdataframe/_filter.py b/verticapy/core/vdataframe/_filter.py index 254c16fa9..02a4a1a88 100755 --- a/verticapy/core/vdataframe/_filter.py +++ b/verticapy/core/vdataframe/_filter.py @@ -1188,7 +1188,7 @@ def filter( f"The expression '{conditions}' is incorrect.\n" "Nothing was filtered." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") if raise_error: raise (e) return self diff --git a/verticapy/core/vdataframe/_machine_learning.py b/verticapy/core/vdataframe/_machine_learning.py index 8426b8786..ad3cb97ce 100755 --- a/verticapy/core/vdataframe/_machine_learning.py +++ b/verticapy/core/vdataframe/_machine_learning.py @@ -695,7 +695,7 @@ def chaid_columns( f"vDataColumn '{col}' has a too high cardinality " f"(> {max_cardinality}). This vDataColumn was ignored." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") for col in remove_cols: columns_tmp.remove(col) return columns_tmp diff --git a/verticapy/core/vdataframe/_plotting.py b/verticapy/core/vdataframe/_plotting.py index 05ce38fa5..fd172c64c 100755 --- a/verticapy/core/vdataframe/_plotting.py +++ b/verticapy/core/vdataframe/_plotting.py @@ -3752,7 +3752,7 @@ def hist( f"The Virtual Column {self._alias} is not " "numerical. A bar chart will be drawn instead." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") if by: return self._parent.bar( columns=[self._alias, by], diff --git a/verticapy/core/vdataframe/_scaler.py b/verticapy/core/vdataframe/_scaler.py index c680cc8ec..d5cb9ecae 100755 --- a/verticapy/core/vdataframe/_scaler.py +++ b/verticapy/core/vdataframe/_scaler.py @@ -195,7 +195,7 @@ def scale( f"The vDataColumn {column} was skipped.\n" "Scaler only accept numerical data types." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") return self normalize = scale @@ -356,7 +356,7 @@ def scale( if self.isbool(): warning_message = "Scaler doesn't work on booleans" - print_message(warning_message, "Warning") + print_message(warning_message, "warning") elif self.isnum(): if method == "zscore": @@ -368,7 +368,7 @@ def scale( f"Can not scale {self} using a " "Z-Score - The Standard Deviation is null !" ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") return self elif (n == 1) and (self._parent[by[0]].nunique() < 50): try: @@ -465,7 +465,7 @@ def scale( "parameter 'by' is empty\nIf you want to scale the data by " "grouping by elements, please use a method in zscore|minmax" ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") return self mad, med = self.aggregate(["mad", "approx_median"]).values[self._alias] mad *= 1.4826 @@ -485,7 +485,7 @@ def scale( f"Can not scale {self} using a " "Robust Z-Score - The MAD is null !" ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") return self elif method == "minmax": @@ -497,7 +497,7 @@ def scale( f"Can not scale {self} using " "the MIN and the MAX. MAX = MIN !" ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") return self elif n == 1: try: diff --git a/verticapy/core/vdataframe/_sys.py b/verticapy/core/vdataframe/_sys.py index f1af0f75a..f36599322 100755 --- a/verticapy/core/vdataframe/_sys.py +++ b/verticapy/core/vdataframe/_sys.py @@ -269,7 +269,7 @@ def _get_sort_syntax(self, columns: Union[dict, SQLColumns]) -> str: f"Method of {column_name} must be in (asc, desc), " f"found '{columns[col].lower()}'\nThis column was ignored." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") else: order_by += [f"{column_name} {columns[col].upper()}"] else: @@ -404,7 +404,7 @@ def current_relation(self, reindent: bool = True, split: bool = False) -> str: .. ipython:: python - print_message(vdf.current_relation()) + print(vdf.current_relation()) If we make any changes to the :py:class:`~vDataFrame`, those will also be reflected in the ``current_relation``. @@ -418,7 +418,7 @@ def current_relation(self, reindent: bool = True, split: bool = False) -> str: .. ipython:: python - print_message(vdf.current_relation()) + print(vdf.current_relation()) .. seealso:: @@ -789,7 +789,7 @@ def explain(self, digraph: bool = False) -> str: .. ipython:: python - print_message(vdf.explain()) + print(vdf.explain()) .. seealso:: diff --git a/verticapy/core/vdataframe/base.py b/verticapy/core/vdataframe/base.py index 465bad6d0..251a4e07f 100755 --- a/verticapy/core/vdataframe/base.py +++ b/verticapy/core/vdataframe/base.py @@ -689,7 +689,7 @@ def __init__( "resolve this issue, provide aliases to your " "queries." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") self._vars["has_dpnames"] = True # Creating the vDataColumns diff --git a/verticapy/jupyter/extensions/chart_magic.py b/verticapy/jupyter/extensions/chart_magic.py index f8530b1d8..b23c7d90c 100644 --- a/verticapy/jupyter/extensions/chart_magic.py +++ b/verticapy/jupyter/extensions/chart_magic.py @@ -721,7 +721,7 @@ def chart_magic( warning_message = ( f"\u26A0 Warning : The option '{option}' doesn't exist - skipping." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") if "-f" in options and "-c" in options: raise ValueError( diff --git a/verticapy/jupyter/extensions/sql_magic.py b/verticapy/jupyter/extensions/sql_magic.py index 4f7359f40..2c56d127a 100644 --- a/verticapy/jupyter/extensions/sql_magic.py +++ b/verticapy/jupyter/extensions/sql_magic.py @@ -679,7 +679,7 @@ def sql_magic( .. ipython:: python file = open("titanic_age_clean.csv", "r") - print_message(file.read()) + print(file.read()) file.close() To export the results of @@ -718,7 +718,7 @@ def sql_magic( .. ipython:: python file = open("titanic_age_clean.json", "r") - print_message(file.read()) + print(file.read()) file.close() Execute SQL files @@ -822,7 +822,7 @@ def sql_magic( f"\u26A0 Warning : The option '{option}' doesn't " "exist, it was skipped." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") if "-f" in options and "-c" in options: raise ValueError( @@ -865,7 +865,7 @@ def sql_magic( ) if external_queries: - print_message(warning_message, "Warning") + print_message(warning_message, "warning") n, i, all_split = len(queries), 0, [] diff --git a/verticapy/machine_learning/model_selection/statistical_tests/ols.py b/verticapy/machine_learning/model_selection/statistical_tests/ols.py index 7c3d51084..bc621b859 100755 --- a/verticapy/machine_learning/model_selection/statistical_tests/ols.py +++ b/verticapy/machine_learning/model_selection/statistical_tests/ols.py @@ -23,7 +23,6 @@ import verticapy._config.config as conf from verticapy._typing import NoneType, SQLColumns, SQLRelation -from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type from verticapy._utils._gen import gen_tmp_name @@ -169,7 +168,7 @@ def het_breuschpagan( .. ipython:: python - print_message(lm_statistic, lm_pvalue, f_statistic, f_pvalue) + print(lm_statistic, lm_pvalue, f_statistic, f_pvalue) As the noise was not heteroscedestic, we got higher p_value scores and lower statistics score. @@ -279,7 +278,7 @@ def het_breuschpagan( .. ipython:: python - print_message(lm_statistic, lm_pvalue, f_statistic, f_pvalue) + print(lm_statistic, lm_pvalue, f_statistic, f_pvalue) .. note:: @@ -441,7 +440,7 @@ def het_goldfeldquandt( .. ipython:: python - print_message(statistic, pvalue) + print(statistic, pvalue) As the noise was not heteroscedestic, we got higher p_value scores and lower statistics score. @@ -528,7 +527,7 @@ def het_goldfeldquandt( .. ipython:: python - print_message(statistic, pvalue) + print(statistic, pvalue) .. note:: @@ -718,7 +717,7 @@ def het_white( .. ipython:: python - print_message(lm_statistic, lm_pvalue, f_statistic, f_pvalue) + print(lm_statistic, lm_pvalue, f_statistic, f_pvalue) As the noise was not heteroscedestic, we got higher p_value scores and lower statistics score. @@ -828,7 +827,7 @@ def het_white( .. ipython:: python - print_message(lm_statistic, lm_pvalue, f_statistic, f_pvalue) + print(lm_statistic, lm_pvalue, f_statistic, f_pvalue) .. note:: diff --git a/verticapy/machine_learning/vertica/base.py b/verticapy/machine_learning/vertica/base.py index 46366cbc8..e00dc2e06 100755 --- a/verticapy/machine_learning/vertica/base.py +++ b/verticapy/machine_learning/vertica/base.py @@ -1194,7 +1194,7 @@ def set_params(self, parameters: Optional[dict] = None, **kwargs) -> None: warning_message = ( f"parameter 'parameters' got an unexpected keyword argument '{p}'" ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") new_parameters[p] = parameters[p] self.__init__(name=self.model_name, **new_parameters) diff --git a/verticapy/machine_learning/vertica/neighbors.py b/verticapy/machine_learning/vertica/neighbors.py index 2e73cff3b..22b592405 100755 --- a/verticapy/machine_learning/vertica/neighbors.py +++ b/verticapy/machine_learning/vertica/neighbors.py @@ -2340,7 +2340,7 @@ def _density_compute( f"Wrong xlim for the vDataColumn {column}.\n" "The max and the min will be used instead." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") x_min, x_max = vdf.agg( func=["min", "max"], columns=[column] ).transpose()[column] diff --git a/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py b/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py index 690404d47..fe36577a2 100644 --- a/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py +++ b/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py @@ -206,7 +206,9 @@ def freeze_model_from_file( def save_graph(frozen_func, frozen_out_path, frozen_graph_file): - print_message("Saving frozen model to: " + os.path.join(frozen_out_path, frozen_graph_file)) + print_message( + "Saving frozen model to: " + os.path.join(frozen_out_path, frozen_graph_file) + ) tf.io.write_graph( graph_or_graph_def=frozen_func.graph, logdir=frozen_out_path, @@ -254,7 +256,9 @@ def gen_tensor_list(tensors): print_message( "3. (Optional) Input/output Vertica column type in prediction (0 (default): primitive; 1: complex)" ) - print_message(" Use primitive if you want one value stored in each row/column cell.") + print_message( + " Use primitive if you want one value stored in each row/column cell." + ) print_message(" Use complex if you want to store the data in Vertica arrays.") print_message( "Example call: ./freeze_tf_model.py path/to/saved/model my_frozen_model 0" @@ -270,4 +274,6 @@ def gen_tensor_list(tensors): elif len(sys.argv) == 4: freeze_model_from_file(str(sys.argv[1]), str(sys.argv[2]), str(sys.argv[3])) else: - print_message("Invalid number of arguments.") # unreachable, just here for completeness + print_message( + "Invalid number of arguments." + ) # unreachable, just here for completeness diff --git a/verticapy/mlops/model_tracking/base.py b/verticapy/mlops/model_tracking/base.py index a9f95c269..d44b9c7a5 100644 --- a/verticapy/mlops/model_tracking/base.py +++ b/verticapy/mlops/model_tracking/base.py @@ -206,7 +206,7 @@ def __init__( "The experiment will not be backed up in the database " "when experiment_table is not specified." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") if self.experiment_type == "clustering" or ( self.experiment_type == "auto" diff --git a/verticapy/performance/vertica/collection/collection_tables.py b/verticapy/performance/vertica/collection/collection_tables.py index 38b761472..93eb19c5d 100644 --- a/verticapy/performance/vertica/collection/collection_tables.py +++ b/verticapy/performance/vertica/collection/collection_tables.py @@ -23,7 +23,6 @@ import pandas as pd -from verticapy._utils._print import print_message from verticapy.core.parsers.pandas import read_pandas from verticapy.core.vdataframe import vDataFrame @@ -131,7 +130,7 @@ class TableMetadata: .. code-block:: python - print_message(f"JSON obj = {tmd.to_json()}") + print(f"JSON obj = {tmd.to_json()}") The output will be: @@ -189,7 +188,7 @@ def __init__(self, file_name: Path, table_type: AllTableTypes, exported_rows: in .. code-block:: python - print_message(f"JSON obj = {tmd.to_json()}") + print(f"JSON obj = {tmd.to_json()}") The output will be: @@ -252,7 +251,7 @@ def to_json(self) -> str: .. code-block:: python - print_message(f"JSON obj = {tmd.to_json()}") + print(f"JSON obj = {tmd.to_json()}") The output will be: @@ -320,7 +319,7 @@ class ExportMetadata: .. code-block:: python - print_message(f"JSON obj = {exp_md.to_json()}") + print(f"JSON obj = {exp_md.to_json()}") The output will be: @@ -390,7 +389,7 @@ def __init__( .. code-block:: python - print_message(f"JSON obj = {exp_md.to_json()}") + print(f"JSON obj = {exp_md.to_json()}") The output will be: @@ -465,7 +464,7 @@ def to_json(self) -> str: .. code-block:: python - print_message(f"JSON obj = {exp_md.to_json()}") + print(f"JSON obj = {exp_md.to_json()}") The output will be: @@ -539,7 +538,7 @@ def write_to_file(self) -> None: exp_md.write_to_file() with open("export_meta.json", "r") as readf: - print_message(f"JSON obj = {readf.read()}") + print(f"JSON obj = {readf.read()}") The output will be: diff --git a/verticapy/performance/vertica/collection/profile_export.py b/verticapy/performance/vertica/collection/profile_export.py index 0bb3ff99b..a44639520 100644 --- a/verticapy/performance/vertica/collection/profile_export.py +++ b/verticapy/performance/vertica/collection/profile_export.py @@ -23,8 +23,6 @@ import pandas as pd - -from verticapy._utils._print import print_message from verticapy._utils._sql._sys import _executeSQL from verticapy.core.vdataframe import vDataFrame from verticapy.core.parsers.pandas import read_pandas @@ -70,7 +68,7 @@ class ProfileExportError(Exception): try: exporter.export() except ProfileExportError as err: - print_message(f"Observed a ProfileExport error") + print(f"Observed a ProfileExport error") The output will be: @@ -158,7 +156,7 @@ class ProfileExport: tfile = tarfile.open("query_requests_example_001.tar") for f in tfile.getnames(): - print_message(f"Tarball contains path: {f}") + print(f"Tarball contains path: {f}") The output will be: @@ -221,7 +219,7 @@ def __init__( .. code-block:: python - print_message(f"Target schema is {exporter.target_schema}\n" + print(f"Target schema is {exporter.target_schema}\n" f"Key is {exporter.key}\n" f"filename is {exporter.filename}") @@ -277,7 +275,7 @@ def tmp_path(self) -> Path: .. code-block:: python - print_message(f"Temp path = {exporter.tmp_path}") + print(f"Temp path = {exporter.tmp_path}") The output will be the current working directory. For this example, let's assume the current working directory is ``/home/u1``. @@ -324,7 +322,7 @@ def tmp_path(self, val: os.PathLike) -> None: .. code-block:: python - print_message(f"Temp path = {exporter.tmp_path}") + print(f"Temp path = {exporter.tmp_path}") The output will be: @@ -415,7 +413,7 @@ def export(self) -> None: tfile = tarfile.open("query_requests_example_001.tar") for f in tfile.getnames(): - print_message(f"Tarball contains path: {f}") + print(f"Tarball contains path: {f}") The output will be: diff --git a/verticapy/performance/vertica/qprof.py b/verticapy/performance/vertica/qprof.py index 5b49fb59d..e1ccfba34 100755 --- a/verticapy/performance/vertica/qprof.py +++ b/verticapy/performance/vertica/qprof.py @@ -425,13 +425,13 @@ class QueryProfiler: tid = qprof.transaction_id sid = qprof.statement_id - print_message(f"tid={tid};sid={sid}") + print(f"tid={tid};sid={sid}") Or simply: .. ipython:: python - print_message(qprof.transactions) + print(qprof.transactions) To avoid recomputing a query, you can also directly use its statement @@ -1070,7 +1070,7 @@ def __init__( "supported. A new key will be then generated: " f"{self.key_id}" ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") else: if isinstance(key_id, int): self.key_id = str(key_id) @@ -1210,7 +1210,7 @@ def __init__( "\nIt might be still running. This transaction" " will be skipped." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") session_params_non_default += [ self._get_current_session_params_non_default() ] @@ -1562,7 +1562,9 @@ def _create_copy_v_table(self, print_info: bool = True) -> None: print_message( f"The key used to build up the tables is: {self.key_id}\n" ) - print_message("You can access the key by using the 'key_id' attribute.") + print_message( + "You can access the key by using the 'key_id' attribute." + ) exists = False idx += 1 @@ -1599,7 +1601,7 @@ def _create_copy_v_table(self, print_info: bool = True) -> None: " to skip the table creation and to use the existing " "ones.\n\nError Details:\n" + str(e) ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") self.target_tables = target_tables def _insert_copy_v_table( @@ -1671,7 +1673,7 @@ def _insert_copy_v_table( f"{transactions} in the relation {new_schema}.{new_table}.\n" "\n\nError Details:\n" + str(e) ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") self.__init__( key_id=self.key_id, target_schema=self.target_schema, @@ -1688,7 +1690,7 @@ def _insert_copy_v_table( f"{transactions}\n" "Are you sure that they exist?" ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") def _check_v_table( self, iterchecks: bool = True, ignore_operators_check: bool = True @@ -1770,7 +1772,9 @@ def _check_v_table( jointables += [current_table] relations += [f"{sc}.{tb}"] if conf.get_option("print_info"): - print_message("Checking all the tables consistency using a single SQL query...") + print_message( + "Checking all the tables consistency using a single SQL query..." + ) query = ( "SELECT " + ", ".join(select) @@ -1868,7 +1872,7 @@ def _check_v_table( "removed, especially if you are directly working on the " "performance tables." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") def _set_request_qd(self): """ @@ -5057,7 +5061,7 @@ def export_profile(self, filename: os.PathLike) -> None: tfile = tarfile.open("query_requests_example_001.tar") for f in tfile.getnames(): - print_message(f"Tarball contains path: {f}") + print(f"Tarball contains path: {f}") The output will be: @@ -5186,7 +5190,7 @@ def import_profile( .. code-block:: python - print_message(f"First query duration was {qprof_imported.get_qduration()} seconds") + print(f"First query duration was {qprof_imported.get_qduration()} seconds") Let's assume the query had a duration of 3.14 seconds. The output will be: diff --git a/verticapy/pipeline/_transform.py b/verticapy/pipeline/_transform.py index 35574e49d..4e5ef95c2 100644 --- a/verticapy/pipeline/_transform.py +++ b/verticapy/pipeline/_transform.py @@ -20,7 +20,6 @@ """ from queue import Queue -from verticapy._utils._print import print_message from verticapy.core.vdataframe.base import vDataFrame @@ -138,7 +137,7 @@ def transformation(transform: dict, table: str) -> vDataFrame: transformed_vdf = transformation(transform, table) # Display the transformed vDataFrame - print_message(transformed_vdf) + print(transformed_vdf) """ vdf = vDataFrame(table) column_queue = Queue() diff --git a/verticapy/plotting/_highcharts/scatter.py b/verticapy/plotting/_highcharts/scatter.py index 713f8a8dc..4366d2515 100755 --- a/verticapy/plotting/_highcharts/scatter.py +++ b/verticapy/plotting/_highcharts/scatter.py @@ -122,7 +122,7 @@ def draw(self, chart: Optional[HChart] = None, **style_kwargs) -> HChart: has_cmap = self.layout["has_cmap"] if has_cmap: warning_message = f"The parameter {has_cmap} is not supported on the Highchart API. It is ignored." - print_message(warning_message, "Warning") + print_message(warning_message, "warning") chart, style_kwargs = self._get_chart(chart, style_kwargs=style_kwargs) chart.set_dict_options(self.init_style) chart.set_dict_options(style_kwargs) diff --git a/verticapy/plotting/_utils.py b/verticapy/plotting/_utils.py index 8930e7ac5..071185bd1 100755 --- a/verticapy/plotting/_utils.py +++ b/verticapy/plotting/_utils.py @@ -103,7 +103,7 @@ def get_plotting_lib( "function.\nThe following example sets matplotlib as graphical library:\n" "import verticapy\nverticapy.set_option('plotting_lib', 'matplotlib')" ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") if lib == "plotly": vpy_plt = vpy_plotly_plt kwargs = {"fig": chart, **plotly_kwargs, **style_kwargs} diff --git a/verticapy/plotting/base.py b/verticapy/plotting/base.py index 244c22356..7cdf59915 100755 --- a/verticapy/plotting/base.py +++ b/verticapy/plotting/base.py @@ -863,7 +863,7 @@ def _compute_hists_params( f"The Virtual Column {col} is not numerical." " Its histogram will not be drawn." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") if not columns_: raise ValueError("No quantitative feature to plot.") columns_, by = vdf.format_colnames(columns_, by) diff --git a/verticapy/sdk/vertica/udf/gen.py b/verticapy/sdk/vertica/udf/gen.py index 1769d4d18..cc9dea943 100755 --- a/verticapy/sdk/vertica/udf/gen.py +++ b/verticapy/sdk/vertica/udf/gen.py @@ -17,7 +17,6 @@ import os from typing import Optional, Union -from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type @@ -110,13 +109,13 @@ def generate_lib_udf( .. ipython:: python - print_message(udx_str) + print(udx_str) Print the SQL statements that install the function: .. ipython:: python - print_message("\\n".join(udx_sql)) + print("\\n".join(udx_sql)) .. note:: diff --git a/verticapy/sdk/vertica/udf/load.py b/verticapy/sdk/vertica/udf/load.py index 5f718ed8e..da981bc37 100755 --- a/verticapy/sdk/vertica/udf/load.py +++ b/verticapy/sdk/vertica/udf/load.py @@ -140,7 +140,7 @@ def import_lib_udf( _executeSQL(query, title=f"UDF installation. [step {idx}]") return True except Exception as e: - print_message(e, "Warning") + print_message(e, "warning") return False finally: os.remove(f"{directory}/{file_name}") diff --git a/verticapy/sql/dtypes.py b/verticapy/sql/dtypes.py index 00f2f8cb5..2ce541fe3 100644 --- a/verticapy/sql/dtypes.py +++ b/verticapy/sql/dtypes.py @@ -194,7 +194,7 @@ def get_data_types( "As parameter 'table_name' is defined, " "parameter 'expression' is ignored." ) - print_message(warning_message, "Warning") + print_message(warning_message, "warning") if isinstance(current_cursor(), vertica_python.vertica.cursor.Cursor) and not ( table_name ): diff --git a/verticapy/sql/geo/index.py b/verticapy/sql/geo/index.py index d1654931f..60df770d8 100755 --- a/verticapy/sql/geo/index.py +++ b/verticapy/sql/geo/index.py @@ -455,7 +455,7 @@ def rename_index(source: str, dest: str, overwrite: bool = False) -> bool: ) except Exception as e: - print_message(str(e), "Warning") + print_message(str(e), "warning") return False return True diff --git a/verticapy/sql/insert.py b/verticapy/sql/insert.py index ef4a4945f..c4f436278 100755 --- a/verticapy/sql/insert.py +++ b/verticapy/sql/insert.py @@ -227,7 +227,7 @@ def insert_into( total_rows += 1 except Exception as e: warning_message = f"Line {i} was skipped.\n{e}" - print_message(warning_message, "Warning") + print_message(warning_message, "warning") if genSQL: return sql else: From 2d9c506dd2528e1e8e4e544781e74ff974d73cd4 Mon Sep 17 00:00:00 2001 From: Badr Date: Wed, 2 Oct 2024 05:41:28 -0400 Subject: [PATCH 3/7] correction 3 --- verticapy/_utils/_print.py | 12 ++++++-- verticapy/connection/connect.py | 6 ++-- verticapy/core/parsers/csv.py | 6 +--- verticapy/core/parsers/json.py | 2 +- verticapy/core/parsers/shp.py | 5 +--- verticapy/core/vdataframe/_aggregate.py | 13 ++++----- verticapy/core/vdataframe/_encoding.py | 5 ++-- verticapy/core/vdataframe/_fill.py | 6 ++-- verticapy/core/vdataframe/_filter.py | 27 +++++++---------- verticapy/core/vdataframe/_math.py | 2 +- verticapy/core/vdataframe/_scaler.py | 2 +- verticapy/jupyter/extensions/chart_magic.py | 2 +- verticapy/jupyter/extensions/sql_magic.py | 21 +++++--------- verticapy/machine_learning/vertica/base.py | 6 ++-- .../machine_learning/vertica/tsa/base.py | 3 +- .../machine_learning/vertica/tsa/ensemble.py | 3 +- verticapy/performance/vertica/qprof.py | 29 ++++++++----------- verticapy/plotting/base.py | 2 +- 18 files changed, 63 insertions(+), 89 deletions(-) diff --git a/verticapy/_utils/_print.py b/verticapy/_utils/_print.py index a4b210ba9..b6b6455ed 100644 --- a/verticapy/_utils/_print.py +++ b/verticapy/_utils/_print.py @@ -16,8 +16,14 @@ """ import warnings +from IPython.display import display, HTML -def print_message(message: str, mtype: Literal["auto", "warning"] = "auto") -> None: +import verticapy._config.config as conf + + +def print_message( + message: str, mtype: Literal["print", "warning", "display"] = "print" +) -> None: """ Prints the input message or warning. This function is used to manage the @@ -26,5 +32,7 @@ def print_message(message: str, mtype: Literal["auto", "warning"] = "auto") -> N mtype = mtype.lower().strip() if mtype == "warning": warnings.warn(message, Warning) - elif mtype == "auto": + elif mtype == "print" and conf.get_option("print_info"): print(message) + elif mtype == "display" and conf.get_option("print_info"): + display(HTML(message)) diff --git a/verticapy/connection/connect.py b/verticapy/connection/connect.py index d12db450e..6f4cfdfd6 100755 --- a/verticapy/connection/connect.py +++ b/verticapy/connection/connect.py @@ -144,8 +144,7 @@ def connect(section: str, dsn: Optional[str] = None) -> None: gb_conn.set_connection( vertica_connection(section, dsn, config=None), section, dsn ) - if conf.get_option("print_info"): - print_message("Connected Successfully!") + print_message("Connected Successfully!") except OAuthTokenRefreshError as error: print_message( "Access Denied: Your authentication credentials are incorrect or have expired. Please retry" @@ -157,8 +156,7 @@ def connect(section: str, dsn: Optional[str] = None) -> None: gb_conn.set_connection( vertica_connection(section, dsn, config=None), section, dsn ) - if conf.get_option("print_info"): - print_message("Connected Successfully!") + print_message("Connected Successfully!") except OAuthTokenRefreshError as error: print_message("Error persists:") raise error diff --git a/verticapy/core/parsers/csv.py b/verticapy/core/parsers/csv.py index 8634725dd..1bcbe9f0a 100755 --- a/verticapy/core/parsers/csv.py +++ b/verticapy/core/parsers/csv.py @@ -937,11 +937,7 @@ def read_csv( query2, title="Ingesting the data.", ) - if ( - not insert - and not temporary_local_table - and conf.get_option("print_info") - ): + if not insert and not temporary_local_table: print_message( f"The table {input_relation} has been successfully created." ) diff --git a/verticapy/core/parsers/json.py b/verticapy/core/parsers/json.py index 676ef28fe..91c3aa9a6 100755 --- a/verticapy/core/parsers/json.py +++ b/verticapy/core/parsers/json.py @@ -799,7 +799,7 @@ def read_json( query3, title="Creating table.", ) - if not temporary_local_table and conf.get_option("print_info"): + if not temporary_local_table: print_message( f"The table {input_relation} has been successfully created." ) diff --git a/verticapy/core/parsers/shp.py b/verticapy/core/parsers/shp.py index f31f534b7..c63a14739 100755 --- a/verticapy/core/parsers/shp.py +++ b/verticapy/core/parsers/shp.py @@ -125,8 +125,5 @@ def read_shp( PARSER STV_ShpParser();""", title="Ingesting the data.", ) - if conf.get_option("print_info"): - print_message( - f'The table "{schema}"."{table_name}" has been successfully created.' - ) + print_message(f'The table "{schema}"."{table_name}" has been successfully created.') return vDataFrame(table_name, schema=schema) diff --git a/verticapy/core/vdataframe/_aggregate.py b/verticapy/core/vdataframe/_aggregate.py index 8f8c75275..8f4f37c7c 100755 --- a/verticapy/core/vdataframe/_aggregate.py +++ b/verticapy/core/vdataframe/_aggregate.py @@ -1022,13 +1022,12 @@ def describe( if pre_comp == "VERTICAPY_NOT_PRECOMPUTED": col_to_compute += [column] break - elif conf.get_option("print_info"): - warning_message = ( - f"The vDataColumn {column} is not numerical, it was ignored." - "\nTo get statistical information about all different " - "variables, please use the parameter method = 'categorical'." - ) - print_message(warning_message, "warning") + warning_message = ( + f"The vDataColumn {column} is not numerical, it was ignored." + "\nTo get statistical information about all different " + "variables, please use the parameter method = 'categorical'." + ) + print_message(warning_message, "warning") for column in columns: if column not in col_to_compute: values["index"] += [column.replace('"', "")] diff --git a/verticapy/core/vdataframe/_encoding.py b/verticapy/core/vdataframe/_encoding.py index 90830c4da..ba821fd79 100755 --- a/verticapy/core/vdataframe/_encoding.py +++ b/verticapy/core/vdataframe/_encoding.py @@ -347,7 +347,7 @@ def one_hot_encode( self[column].one_hot_encode( "", prefix_sep, drop_first, use_numbers_as_suffix ) - elif cols_hand and conf.get_option("print_info"): + elif cols_hand: warning_message = ( f"The vDataColumn '{column}' was ignored because of " "its high cardinality.\nIncrease the parameter " @@ -1646,6 +1646,5 @@ def mean_encode(self, response: str) -> "vDataFrame": f"[Mean Encode]: The vDataColumn {self} was transformed " f"using a mean encoding with {response} as Response Column." ) - if conf.get_option("print_info"): - print_message("The mean encoding was successfully done.") + print_message("The mean encoding was successfully done.") return self._parent diff --git a/verticapy/core/vdataframe/_fill.py b/verticapy/core/vdataframe/_fill.py index ce429d452..e22276786 100755 --- a/verticapy/core/vdataframe/_fill.py +++ b/verticapy/core/vdataframe/_fill.py @@ -996,14 +996,12 @@ def fillna( ) total = int(total) conj = "s were " if total > 1 else " was " - if conf.get_option("print_info"): - print_message(f"{total} element{conj}filled.") + print_message(f"{total} element{conj}filled.") self._parent._add_to_history( f"[Fillna]: {total} {self} missing value{conj} filled." ) else: - if conf.get_option("print_info"): - print_message("Nothing was filled.") + print_message("Nothing was filled.") self._transf = [t for t in copy_trans] for s in sauv: self._catalog[s] = sauv[s] diff --git a/verticapy/core/vdataframe/_filter.py b/verticapy/core/vdataframe/_filter.py index 02a4a1a88..4edc80b3e 100755 --- a/verticapy/core/vdataframe/_filter.py +++ b/verticapy/core/vdataframe/_filter.py @@ -859,8 +859,7 @@ def drop_duplicates(self, columns: Optional[SQLColumns] = None) -> "vDataFrame": ) self.filter(f'"{name}" = 1') self._vars["exclude_columns"] += [f'"{name}"'] - elif conf.get_option("print_info"): - print_message("No duplicates detected.") + print_message("No duplicates detected.") return self @save_verticapy_logs @@ -1001,7 +1000,6 @@ def dropna(self, columns: Optional[SQLColumns] = None) -> "vDataFrame": conf.set_option("print_info", False) self[column].dropna() conf.set_option("print_info", print_info) - if conf.get_option("print_info"): total -= self.shape()[0] if total == 0: print_message("Nothing was filtered.") @@ -1153,14 +1151,12 @@ def filter( ) count -= self.shape()[0] if count > 0: - if conf.get_option("print_info"): - print_message(f"{count} element{conj}filtered") + print_message(f"{count} element{conj}filtered") self._add_to_history( f"[Filter]: {count} element{conj}filtered " f"using the filter '{conditions}'" ) - elif conf.get_option("print_info"): - print_message("Nothing was filtered.") + print_message("Nothing was filtered.") else: max_pos = 0 columns_tmp = copy.deepcopy(self._vars["columns"]) @@ -1183,12 +1179,11 @@ def filter( count -= new_count except QueryError as e: del self._vars["where"][-1] - if conf.get_option("print_info"): - warning_message = ( - f"The expression '{conditions}' is incorrect.\n" - "Nothing was filtered." - ) - print_message(warning_message, "warning") + warning_message = ( + f"The expression '{conditions}' is incorrect.\n" + "Nothing was filtered." + ) + print_message(warning_message, "warning") if raise_error: raise (e) return self @@ -1196,8 +1191,7 @@ def filter( self._update_catalog(erase=True) self._vars["count"] = new_count conj = "s were " if count > 1 else " was " - if conf.get_option("print_info") and "print_info" not in kwargs: - print_message(f"{count} element{conj}filtered.") + print_message(f"{count} element{conj}filtered.") conditions_clean = clean_query(conditions) self._add_to_history( f"[Filter]: {count} element{conj}filtered using " @@ -1205,8 +1199,7 @@ def filter( ) else: del self._vars["where"][-1] - if conf.get_option("print_info") and "print_info" not in kwargs: - print_message("Nothing was filtered.") + print_message("Nothing was filtered.") return self @save_verticapy_logs diff --git a/verticapy/core/vdataframe/_math.py b/verticapy/core/vdataframe/_math.py index 2e6f67829..d281127e1 100755 --- a/verticapy/core/vdataframe/_math.py +++ b/verticapy/core/vdataframe/_math.py @@ -415,7 +415,7 @@ def analytic( "iqr", "sem", ) or ("%" in func): - if order_by and not conf.get_option("print_info"): + if order_by: print_message( f"\u26A0 '{func}' analytic method doesn't need an " "order by clause, it was ignored" diff --git a/verticapy/core/vdataframe/_scaler.py b/verticapy/core/vdataframe/_scaler.py index d5cb9ecae..2666abaab 100755 --- a/verticapy/core/vdataframe/_scaler.py +++ b/verticapy/core/vdataframe/_scaler.py @@ -190,7 +190,7 @@ def scale( self[column].scale(method=method) elif (no_cols) and (self[column].isbool()): pass - elif conf.get_option("print_info"): + else: warning_message = ( f"The vDataColumn {column} was skipped.\n" "Scaler only accept numerical data types." diff --git a/verticapy/jupyter/extensions/chart_magic.py b/verticapy/jupyter/extensions/chart_magic.py index b23c7d90c..e315df47f 100644 --- a/verticapy/jupyter/extensions/chart_magic.py +++ b/verticapy/jupyter/extensions/chart_magic.py @@ -717,7 +717,7 @@ def chart_magic( raise ValueError("Duplicate option '-k'.") options["-k"] = options_dict[option] - elif conf.get_option("print_info"): + else: warning_message = ( f"\u26A0 Warning : The option '{option}' doesn't exist - skipping." ) diff --git a/verticapy/jupyter/extensions/sql_magic.py b/verticapy/jupyter/extensions/sql_magic.py index 2c56d127a..cf53a347f 100644 --- a/verticapy/jupyter/extensions/sql_magic.py +++ b/verticapy/jupyter/extensions/sql_magic.py @@ -817,7 +817,7 @@ def sql_magic( raise ValueError("Duplicate option '-ncols'.") options["-ncols"] = int(options_dict[option]) - elif conf.get_option("print_info"): + else: warning_message = ( f"\u26A0 Warning : The option '{option}' doesn't " "exist, it was skipped." @@ -965,7 +965,7 @@ def sql_magic( except Exception as e: error = str(e) - if conf.get_option("print_info") and ( + if ( "Severity: ERROR, Message: User defined transform must return at least one column" in error and "DBLINK" in error @@ -975,7 +975,7 @@ def sql_magic( elif error: raise QueryError(error) - elif conf.get_option("print_info"): + else: print_message(query_type) else: @@ -1022,13 +1022,11 @@ def sql_magic( final_result = _executeSQL( query, method="fetchfirstelem", print_time_sql=False ) - if final_result and conf.get_option("print_info"): + if final_result: print_message(final_result) - elif ( - query_subtype.upper().startswith(SPECIAL_WORDS) - ) and conf.get_option("print_info"): + elif query_subtype.upper().startswith(SPECIAL_WORDS): print_message(query_subtype.upper()) - elif conf.get_option("print_info"): + else: print_message(query_type) except Exception as e: @@ -1041,8 +1039,7 @@ def sql_magic( in error and "DBLINK" in error ): - if conf.get_option("print_info"): - print_message(query_type) + print_message(query_type) elif error: raise QueryError(error) @@ -1062,9 +1059,7 @@ def sql_magic( # Displaying the time elapsed_time = round(time.time() - start_time, 3) - - if conf.get_option("print_info"): - display(HTML(f"
Execution: {elapsed_time}s
")) + print_message(f"
Execution: {elapsed_time}s
", "display") return result diff --git a/verticapy/machine_learning/vertica/base.py b/verticapy/machine_learning/vertica/base.py index e00dc2e06..27e635e22 100755 --- a/verticapy/machine_learning/vertica/base.py +++ b/verticapy/machine_learning/vertica/base.py @@ -2427,8 +2427,7 @@ def fit( report = self.summarize() if return_report: return report - if conf.get_option("print_info"): - print_message(report) + print_message(report) return None @@ -7995,6 +7994,5 @@ def fit( report = self.summarize() if return_report: return report - if conf.get_option("print_info"): - print_message(report) + print_message(report) return None diff --git a/verticapy/machine_learning/vertica/tsa/base.py b/verticapy/machine_learning/vertica/tsa/base.py index 9ea76a39c..84f564fd9 100755 --- a/verticapy/machine_learning/vertica/tsa/base.py +++ b/verticapy/machine_learning/vertica/tsa/base.py @@ -331,8 +331,7 @@ def fit( report = self.summarize() if return_report: return report - if conf.get_option("print_info"): - print_message(report) + print_message(report) else: self._compute_attributes() return None diff --git a/verticapy/machine_learning/vertica/tsa/ensemble.py b/verticapy/machine_learning/vertica/tsa/ensemble.py index f29da9412..d0b6da719 100755 --- a/verticapy/machine_learning/vertica/tsa/ensemble.py +++ b/verticapy/machine_learning/vertica/tsa/ensemble.py @@ -376,8 +376,7 @@ def fit( self.models_ += [model] if return_report: return report - if conf.get_option("print_info"): - print_message(report) + print_message(report) return None # I/O Methods. diff --git a/verticapy/performance/vertica/qprof.py b/verticapy/performance/vertica/qprof.py index e1ccfba34..322ac0c38 100755 --- a/verticapy/performance/vertica/qprof.py +++ b/verticapy/performance/vertica/qprof.py @@ -1254,7 +1254,7 @@ def __init__( self._create_copy_v_table(print_info=print_info) # SETTING THE requests AND queries durations. - if conf.get_option("print_info") and print_info: + if print_info: print_message("Setting the requests and queries durations...") self._set_request_qd() @@ -1495,7 +1495,7 @@ def _create_copy_v_table(self, print_info: bool = True) -> None: v_temp_table_dict = self._v_table_dict() v_config_table_list = self._v_config_table_list() loop = v_temp_table_dict.items() - if conf.get_option("print_info") and print_info: + if print_info: print_message("Searching the performance tables...") if conf.get_option("tqdm") and print_info: loop = tqdm(loop, total=len(loop)) @@ -1556,7 +1556,7 @@ def _create_copy_v_table(self, print_info: bool = True) -> None: ) ] except: - if conf.get_option("print_info") and idx == 0: + if idx == 0: print_message("Some tables seem to not exist...") print_message("Creating a copy of the performance tables...\n") print_message( @@ -1578,10 +1578,9 @@ def _create_copy_v_table(self, print_info: bool = True) -> None: self.tables_dtypes += [self.v_tables_dtypes[-1]] if not (exists) or (self.overwrite): - if conf.get_option("print_info"): - print_message( - f"Copy of {schema}.{table} created in {new_schema}.{new_table}" - ) + print_message( + f"Copy of {schema}.{table} created in {new_schema}.{new_table}" + ) try: if self.overwrite: _executeSQL( @@ -1640,8 +1639,7 @@ def _insert_copy_v_table( v_temp_table_dict = self._v_table_dict() v_config_table_list = self._v_config_table_list() loop = v_temp_table_dict.items() - if conf.get_option("print_info"): - print_message("Inserting the new transactions...") + print_message("Inserting the new transactions...") if conf.get_option("tqdm"): loop = tqdm(loop, total=len(loop)) idx = 0 @@ -1724,8 +1722,7 @@ def _check_v_table( if iterchecks: if conf.get_option("tqdm"): loop = tqdm(loop, total=len(loop)) - if conf.get_option("print_info"): - print_message("Checking all the tables consistency iteratively...") + print_message("Checking all the tables consistency iteratively...") for tr_id, st_id in loop: for table_name in tables: if table_name not in config_table: @@ -1771,10 +1768,9 @@ def _check_v_table( current_table += " USING (transaction_id, statement_id)" jointables += [current_table] relations += [f"{sc}.{tb}"] - if conf.get_option("print_info"): - print_message( - "Checking all the tables consistency using a single SQL query..." - ) + print_message( + "Checking all the tables consistency using a single SQL query..." + ) query = ( "SELECT " + ", ".join(select) @@ -1813,8 +1809,7 @@ def _check_v_table( inconsistent_dt = "" table_name_list = list(self._v_table_dict()) n = len(self.tables_dtypes) - if conf.get_option("print_info"): - print_message("Checking all the tables data types...") + print_message("Checking all the tables data types...") for i in range(n): table_name = table_name_list[i] table_1 = self.v_tables_dtypes[i] diff --git a/verticapy/plotting/base.py b/verticapy/plotting/base.py index 7cdf59915..06d3d1d0d 100755 --- a/verticapy/plotting/base.py +++ b/verticapy/plotting/base.py @@ -858,7 +858,7 @@ def _compute_hists_params( for col in columns: if vdf[col].isnum() and not (vdf[col].isbool()): columns_ += [col] - elif conf.get_option("print_info"): + else: warning_message = ( f"The Virtual Column {col} is not numerical." " Its histogram will not be drawn." From ba390cfa361c82830a802a8af5706ab708265c60 Mon Sep 17 00:00:00 2001 From: Badr Date: Wed, 2 Oct 2024 05:51:55 -0400 Subject: [PATCH 4/7] Correction 3 --- verticapy/_utils/_print.py | 6 ++++-- verticapy/connection/connect.py | 1 - verticapy/connection/write.py | 16 ++++------------ verticapy/core/vdataframe/_math.py | 1 - verticapy/core/vdataframe/_scaler.py | 1 - verticapy/jupyter/extensions/chart_magic.py | 4 +++- verticapy/jupyter/extensions/sql_magic.py | 4 +++- .../model_selection/statistical_tests/ols.py | 1 - verticapy/machine_learning/vertica/neighbors.py | 1 - verticapy/machine_learning/vertica/pipeline.py | 1 - .../machine_learning/vertica/preprocessing.py | 1 - verticapy/machine_learning/vertica/tsa/base.py | 1 - .../machine_learning/vertica/tsa/ensemble.py | 1 - 13 files changed, 14 insertions(+), 25 deletions(-) diff --git a/verticapy/_utils/_print.py b/verticapy/_utils/_print.py index b6b6455ed..b00f2d437 100644 --- a/verticapy/_utils/_print.py +++ b/verticapy/_utils/_print.py @@ -14,12 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. """ +from typing import Literal import warnings -from IPython.display import display, HTML - import verticapy._config.config as conf +if conf.get_import_success("IPython"): + from IPython.display import display, HTML + def print_message( message: str, mtype: Literal["print", "warning", "display"] = "print" diff --git a/verticapy/connection/connect.py b/verticapy/connection/connect.py index 6f4cfdfd6..5aa95ba51 100755 --- a/verticapy/connection/connect.py +++ b/verticapy/connection/connect.py @@ -21,7 +21,6 @@ from vertica_python.vertica.cursor import Cursor from vertica_python.vertica.connection import Connection -import verticapy._config.config as conf from verticapy._utils._print import print_message from verticapy.connection.errors import ConnectionError, OAuthTokenRefreshError diff --git a/verticapy/connection/write.py b/verticapy/connection/write.py index 5baca2c75..8787e1f64 100755 --- a/verticapy/connection/write.py +++ b/verticapy/connection/write.py @@ -18,7 +18,6 @@ from getpass import getpass import vertica_python -import verticapy._config.config as conf from verticapy._utils._print import print_message from verticapy.connection.errors import ConnectionError, OAuthTokenRefreshError @@ -291,12 +290,6 @@ def new_connection( | :py:func:`~verticapy.connection.set_connection` : Sets the VerticaPy connection. """ - doPrintInfo = conf.get_option("print_info") - - def _printInfo(info): - if doPrintInfo: - print_message(info) - path = get_connection_file() confparser = get_confparser() @@ -312,11 +305,11 @@ def _printInfo(info): if prompt: if not (oauth_access_token := getpass("Input OAuth Access Token:")): - _printInfo("Default value applied: Input left empty.") + print_message("Default value applied: Input left empty.") else: conn_info["oauth_access_token"] = oauth_access_token if not (oath_refresh_token := getpass("Input OAuth Refresh Token:")): - _printInfo("Default value applied: Input left empty.") + print_message("Default value applied: Input left empty.") else: conn_info["oauth_refresh_token"] = oath_refresh_token if not ( @@ -324,7 +317,7 @@ def _printInfo(info): "Input OAuth Client Secret: (OTCAD and public client users should leave this blank)" ) ): - _printInfo("Default value applied: Input left empty.") + print_message("Default value applied: Input left empty.") else: conn_info["oauth_config"]["client_secret"] = client_secret @@ -365,8 +358,7 @@ def _printInfo(info): gb_conn.set_connection( vertica_python.connect(**read_dsn(name, path)), name, path ) - if doPrintInfo: - print_message("Connected Successfully!") + print_message("Connected Successfully!") except OAuthTokenRefreshError as error: print_message("Error persists:") raise error diff --git a/verticapy/core/vdataframe/_math.py b/verticapy/core/vdataframe/_math.py index d281127e1..c6399adc8 100755 --- a/verticapy/core/vdataframe/_math.py +++ b/verticapy/core/vdataframe/_math.py @@ -19,7 +19,6 @@ import re from typing import Literal, Optional, Union, TYPE_CHECKING -import verticapy._config.config as conf from verticapy._typing import PythonNumber, PythonScalar, SQLColumns from verticapy._utils._gen import gen_name from verticapy._utils._map import verticapy_agg_name diff --git a/verticapy/core/vdataframe/_scaler.py b/verticapy/core/vdataframe/_scaler.py index 2666abaab..84d56d95c 100755 --- a/verticapy/core/vdataframe/_scaler.py +++ b/verticapy/core/vdataframe/_scaler.py @@ -20,7 +20,6 @@ from vertica_python.errors import QueryError -import verticapy._config.config as conf from verticapy._typing import NoneType, SQLColumns from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs diff --git a/verticapy/jupyter/extensions/chart_magic.py b/verticapy/jupyter/extensions/chart_magic.py index e315df47f..2efa7a5a6 100644 --- a/verticapy/jupyter/extensions/chart_magic.py +++ b/verticapy/jupyter/extensions/chart_magic.py @@ -19,7 +19,6 @@ from typing import Optional, Literal, Union from IPython.core.magic import needs_local_scope -from IPython.display import display, HTML from vertica_highcharts import Highstock, Highchart @@ -35,6 +34,9 @@ from verticapy.plotting._utils import PlottingUtils +if conf.get_import_success("IPython"): + from IPython.display import display, HTML + CLASS_NAME_MAP = { "auto": None, "area": "MultiLinePlot", diff --git a/verticapy/jupyter/extensions/sql_magic.py b/verticapy/jupyter/extensions/sql_magic.py index cf53a347f..00fde81b8 100644 --- a/verticapy/jupyter/extensions/sql_magic.py +++ b/verticapy/jupyter/extensions/sql_magic.py @@ -28,7 +28,6 @@ from typing import Optional, TYPE_CHECKING from IPython.core.magic import needs_local_scope -from IPython.display import display, HTML import verticapy._config.config as conf from verticapy._utils._object import create_new_vdf @@ -52,6 +51,9 @@ import graphviz from graphviz import Source +if conf.get_import_success("IPython"): + from IPython.display import display, HTML + if TYPE_CHECKING: from verticapy.core.vdataframe.base import vDataFrame diff --git a/verticapy/machine_learning/model_selection/statistical_tests/ols.py b/verticapy/machine_learning/model_selection/statistical_tests/ols.py index bc621b859..f9fa4f757 100755 --- a/verticapy/machine_learning/model_selection/statistical_tests/ols.py +++ b/verticapy/machine_learning/model_selection/statistical_tests/ols.py @@ -21,7 +21,6 @@ from vertica_python.errors import QueryError -import verticapy._config.config as conf from verticapy._typing import NoneType, SQLColumns, SQLRelation from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import format_type diff --git a/verticapy/machine_learning/vertica/neighbors.py b/verticapy/machine_learning/vertica/neighbors.py index 22b592405..4f614d489 100755 --- a/verticapy/machine_learning/vertica/neighbors.py +++ b/verticapy/machine_learning/vertica/neighbors.py @@ -20,7 +20,6 @@ from vertica_python.errors import QueryError -import verticapy._config.config as conf from verticapy._typing import ( NoneType, PlottingObject, diff --git a/verticapy/machine_learning/vertica/pipeline.py b/verticapy/machine_learning/vertica/pipeline.py index 4acaf6b14..73dda651e 100755 --- a/verticapy/machine_learning/vertica/pipeline.py +++ b/verticapy/machine_learning/vertica/pipeline.py @@ -18,7 +18,6 @@ from typing import Literal, Optional -import verticapy._config.config as conf from verticapy._typing import NoneType, SQLColumns, SQLRelation from verticapy._utils._sql._format import format_type from verticapy._utils._sql._collect import save_verticapy_logs diff --git a/verticapy/machine_learning/vertica/preprocessing.py b/verticapy/machine_learning/vertica/preprocessing.py index 743c5cb28..528e6d432 100755 --- a/verticapy/machine_learning/vertica/preprocessing.py +++ b/verticapy/machine_learning/vertica/preprocessing.py @@ -20,7 +20,6 @@ from vertica_python.errors import QueryError -import verticapy._config.config as conf from verticapy._typing import NoneType, SQLColumns, SQLRelation from verticapy._utils._gen import gen_tmp_name from verticapy._utils._sql._collect import save_verticapy_logs diff --git a/verticapy/machine_learning/vertica/tsa/base.py b/verticapy/machine_learning/vertica/tsa/base.py index 84f564fd9..72eaab92f 100755 --- a/verticapy/machine_learning/vertica/tsa/base.py +++ b/verticapy/machine_learning/vertica/tsa/base.py @@ -22,7 +22,6 @@ import numpy as np -import verticapy._config.config as conf from verticapy._typing import ( PlottingObject, NoneType, diff --git a/verticapy/machine_learning/vertica/tsa/ensemble.py b/verticapy/machine_learning/vertica/tsa/ensemble.py index d0b6da719..822bc143f 100755 --- a/verticapy/machine_learning/vertica/tsa/ensemble.py +++ b/verticapy/machine_learning/vertica/tsa/ensemble.py @@ -18,7 +18,6 @@ import copy from typing import Literal, Optional, Union -import verticapy._config.config as conf from verticapy._typing import NoneType, PlottingObject, SQLColumns, SQLRelation from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs From 96ed43db91b3a3ec1f6d7d121b1f93a33ccc0aa7 Mon Sep 17 00:00:00 2001 From: Badr Date: Wed, 2 Oct 2024 06:09:54 -0400 Subject: [PATCH 5/7] PART 4 --- verticapy/_config/config.py | 12 ++++++++++++ verticapy/_utils/_print.py | 14 +++++++++++--- verticapy/_utils/_sql/_sys.py | 8 ++++++-- verticapy/core/tablesample/base.py | 4 ++-- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/verticapy/_config/config.py b/verticapy/_config/config.py index f0a93d2e9..9c3f7d015 100755 --- a/verticapy/_config/config.py +++ b/verticapy/_config/config.py @@ -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. @@ -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]), + ) +) diff --git a/verticapy/_utils/_print.py b/verticapy/_utils/_print.py index b00f2d437..406730387 100644 --- a/verticapy/_utils/_print.py +++ b/verticapy/_utils/_print.py @@ -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)) diff --git a/verticapy/_utils/_sql/_sys.py b/verticapy/_utils/_sql/_sys.py index 39350ee3b..69a44e5d4 100755 --- a/verticapy/_utils/_sql/_sys.py +++ b/verticapy/_utils/_sql/_sys.py @@ -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: @@ -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() diff --git a/verticapy/core/tablesample/base.py b/verticapy/core/tablesample/base.py index a35f5203f..7eee6d09f 100644 --- a/verticapy/core/tablesample/base.py +++ b/verticapy/core/tablesample/base.py @@ -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( @@ -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] From 0a23228e293ffe347bae1e6802f91176df337757 Mon Sep 17 00:00:00 2001 From: Badr Date: Wed, 2 Oct 2024 06:42:36 -0400 Subject: [PATCH 6/7] PART5 - should be the last part of this change. --- verticapy/_utils/_parsers.py | 8 +---- verticapy/_utils/_print.py | 17 +++++++--- verticapy/_utils/_sql/_display.py | 11 +++---- verticapy/_utils/_sql/_format.py | 10 ++---- verticapy/core/vdataframe/_read.py | 6 ++-- verticapy/jupyter/_widgets.py | 10 +++--- verticapy/jupyter/extensions/chart_magic.py | 6 +--- verticapy/jupyter/extensions/sql_magic.py | 3 -- .../performance/vertica/qprof_interface.py | 31 ++++++++++--------- .../machine_learning/champion_challenger.py | 2 +- 10 files changed, 47 insertions(+), 57 deletions(-) diff --git a/verticapy/_utils/_parsers.py b/verticapy/_utils/_parsers.py index 7d47a6009..614b2db78 100755 --- a/verticapy/_utils/_parsers.py +++ b/verticapy/_utils/_parsers.py @@ -26,9 +26,6 @@ import graphviz from graphviz import Source -if conf.get_import_success("IPython"): - from IPython.display import display - # CSV @@ -329,8 +326,5 @@ def parse_explain_graphviz(rows: list[str], display_trees: bool = True) -> list: result += [row] if display_trees: for row in result: - if isinstance(row, str) or not (conf.get_import_success("IPython")): - print_message(row) - else: - display(row) + print_message(row, "display") return result diff --git a/verticapy/_utils/_print.py b/verticapy/_utils/_print.py index 406730387..9535e1f39 100644 --- a/verticapy/_utils/_print.py +++ b/verticapy/_utils/_print.py @@ -20,11 +20,11 @@ import verticapy._config.config as conf if conf.get_import_success("IPython"): - from IPython.display import display, HTML + from IPython.display import display, HTML, Markdown def print_message( - message: str, mtype: Literal["print", "warning", "display"] = "print" + message: str, mtype: Literal["print", "warning", "display", "markdown"] = "print" ) -> None: """ Prints the input message or warning. @@ -41,8 +41,17 @@ def print_message( ): print(message) elif ( - mtype == "display" + mtype in ("display", "markdown") and conf.get_option("print_info") and conf.get_option("verbosity") >= 2 ): - display(HTML(message)) + if conf.get_import_success("IPython"): + try: + if mtype == "markdown": + display(Markdown(message)) + else: + display(HTML(message)) + except: + display(message) + else: + print(message) diff --git a/verticapy/_utils/_sql/_display.py b/verticapy/_utils/_sql/_display.py index ff3376bd6..863daba3e 100755 --- a/verticapy/_utils/_sql/_display.py +++ b/verticapy/_utils/_sql/_display.py @@ -21,9 +21,6 @@ from verticapy._utils._print import print_message from verticapy._utils._sql._format import clean_query, indent_vpy_sql -if conf.get_import_success("IPython"): - from IPython.display import HTML, display - def print_query(query: str, title: Optional[str] = None) -> None: """ @@ -65,9 +62,9 @@ def print_query(query: str, title: Optional[str] = None) -> None: query_print = clean_query(query) query_print = indent_vpy_sql(query) if conf.get_import_success("IPython"): - display(HTML(f"

{title}

")) + print_message(f"

{title}

", "display") query_print = query_print.replace("\n", "
").replace(" ", "   ") - display(HTML(query_print)) + print_message(query_print, "display") else: print_message(f"$ {title} $\n") print_message(query_print) @@ -104,7 +101,9 @@ def print_time(elapsed_time: float) -> None: """ screen_columns = shutil.get_terminal_size().columns if conf.get_import_success("IPython"): - display(HTML(f"
Execution: {round(elapsed_time, 3)}s
")) + print_message( + f"
Execution: {round(elapsed_time, 3)}s
", "display" + ) else: print_message(f"Execution: {round(elapsed_time, 3)}s") print_message("-" * int(screen_columns) + "\n") diff --git a/verticapy/_utils/_sql/_format.py b/verticapy/_utils/_sql/_format.py index b48ed34ed..fc0b7438f 100755 --- a/verticapy/_utils/_sql/_format.py +++ b/verticapy/_utils/_sql/_format.py @@ -28,9 +28,6 @@ from verticapy._typing import NoneType, SQLColumns, SQLExpression from verticapy.errors import ParsingError -if conf.get_import_success("IPython"): - from IPython.display import display, Markdown - """ SQL KEYWORDS """ @@ -640,7 +637,6 @@ def format_query( construct others, simplifying the overall code. """ - display_success = print_sql and conf.get_import_success("IPython") res = clean_query(query) html_res = res @@ -695,15 +691,13 @@ def format_query( .replace("\n", "
") .replace(" ", "    ") ) - if display_success: - display(Markdown(html_res)) if indent_sql: res = indent_vpy_sql(res) if print_sql: - print_message(res) + print_message(res, "markdown") if only_html: return html_res - elif display_success: + elif print_sql: return res, html_res return res, None diff --git a/verticapy/core/vdataframe/_read.py b/verticapy/core/vdataframe/_read.py index fe20beacf..f8fbc08ac 100755 --- a/verticapy/core/vdataframe/_read.py +++ b/verticapy/core/vdataframe/_read.py @@ -22,6 +22,7 @@ import verticapy._config.config as conf from verticapy._typing import SQLColumns from verticapy._utils._object import create_new_vdf +from verticapy._utils._print import print_message from verticapy._utils._sql._cast import to_varchar from verticapy._utils._sql._collect import save_verticapy_logs from verticapy._utils._sql._format import ( @@ -38,9 +39,6 @@ from verticapy.core.vdataframe._utils import vDFUtils, vDCUtils -if conf.get_import_success("IPython"): - from IPython.display import HTML, display - if TYPE_CHECKING: from verticapy.core.vdataframe.base import vDataFrame @@ -187,7 +185,7 @@ def idisplay(self) -> None: It is used when you don't want to activate interactive tables for all :py:class:`~vDataFrame`. """ - return display(HTML(self.copy()._repr_html_(interactive=True))) + return print_message(self.copy()._repr_html_(interactive=True), "display") def get_columns(self, exclude_columns: Optional[SQLColumns] = None) -> list[str]: """ diff --git a/verticapy/jupyter/_widgets.py b/verticapy/jupyter/_widgets.py index ab8708327..f20a98b22 100644 --- a/verticapy/jupyter/_widgets.py +++ b/verticapy/jupyter/_widgets.py @@ -18,10 +18,10 @@ from typing import Any, Literal import verticapy._config.config as conf +from verticapy._utils._print import print_message if conf.get_import_success("IPython"): import ipywidgets as widgets - from IPython.display import display class Visualizer: @@ -86,14 +86,14 @@ def display(self): if self.orientation == "v": settings = widgets.HBox(self.settings_wids) with self.settings_box: - display(settings) + print_message(settings) with self.graph_box: self.graph_box.clear_output(wait=True) - display(graph) + print_message(graph) if self.orientation == "v": - display(widgets.VBox([self.settings_box, self.graph_box])) + print_message(widgets.VBox([self.settings_box, self.graph_box])) return - display(widgets.HBox([self.settings_box, self.graph_box])) + print_message(widgets.HBox([self.settings_box, self.graph_box])) @staticmethod def _accordion(children: list, titles: list) -> widgets.Accordion: diff --git a/verticapy/jupyter/extensions/chart_magic.py b/verticapy/jupyter/extensions/chart_magic.py index 2efa7a5a6..c54f86856 100644 --- a/verticapy/jupyter/extensions/chart_magic.py +++ b/verticapy/jupyter/extensions/chart_magic.py @@ -22,7 +22,6 @@ from vertica_highcharts import Highstock, Highchart -import verticapy._config.config as conf from verticapy._typing import PlottingObject from verticapy._utils._print import print_message from verticapy._utils._sql._collect import save_verticapy_logs @@ -34,9 +33,6 @@ from verticapy.plotting._utils import PlottingUtils -if conf.get_import_success("IPython"): - from IPython.display import display, HTML - CLASS_NAME_MAP = { "auto": None, "area": "MultiLinePlot", @@ -759,7 +755,7 @@ def chart_magic( # Displaying the time elapsed_time = round(time.time() - start_time, 3) - display(HTML(f"
Execution: {elapsed_time}s
")) + print_message(f"
Execution: {elapsed_time}s
", "display") return chart diff --git a/verticapy/jupyter/extensions/sql_magic.py b/verticapy/jupyter/extensions/sql_magic.py index 00fde81b8..4c26e2344 100644 --- a/verticapy/jupyter/extensions/sql_magic.py +++ b/verticapy/jupyter/extensions/sql_magic.py @@ -51,9 +51,6 @@ import graphviz from graphviz import Source -if conf.get_import_success("IPython"): - from IPython.display import display, HTML - if TYPE_CHECKING: from verticapy.core.vdataframe.base import vDataFrame diff --git a/verticapy/performance/vertica/qprof_interface.py b/verticapy/performance/vertica/qprof_interface.py index 032e391ae..30004ceaa 100644 --- a/verticapy/performance/vertica/qprof_interface.py +++ b/verticapy/performance/vertica/qprof_interface.py @@ -19,13 +19,14 @@ from typing import Optional, Union import verticapy._config.config as conf +from verticapy._utils._print import print_message + from verticapy.jupyter._javascript import read_package_file, replace_value from verticapy.jupyter._widgets import Visualizer, Item, makeItems from verticapy.performance.vertica.qprof_stats_tests import QueryProfilerStats from verticapy.performance.vertica.qprof_utility import QprofUtility if conf.get_import_success("IPython"): - from IPython.display import display, HTML import ipywidgets as widgets @@ -420,7 +421,7 @@ def _update_qplan_tree( Callback function that displays the Query Plan Tree. """ # Create an output widget to hold the hourglass and the tree - display(self.output) + print_message(self.output, "display") # Show hourglass in the output before starting long-running task with self.output: @@ -434,7 +435,7 @@ def _update_qplan_tree( [hourglass_icon], layout=widgets.Layout(justify_content="center", align_items="center"), ) - display(vbox) + print_message(vbox, "display") # Processing the inputs and generate the tree (long running task) metric = [ @@ -480,7 +481,7 @@ def _update_qplan_tree( ) box = widgets.HBox([html_widget]) box.layout.justify_content = "center" - display(box) + print_message(box, "display") else: raw = super().get_qplan_tree( metric=metric, @@ -512,7 +513,7 @@ def _update_qplan_tree( with self.output: self.output.clear_output(wait=True) # Clear the hourglass - display(HTML(output_html)) + print_message(output_html, "display") # Update the header after the tree is displayed self._qpt_header.value = ( @@ -794,12 +795,13 @@ def update_qsteps( """ Callback function that displays the Query Execution Steps. """ - display( + print_message( super().get_qsteps_( unit=self.qsteps_controls["unit"], kind=self.qsteps_controls["kind"], categoryorder=self.qsteps_controls["categoryorder"], - ) + ), + "display", ) self._qsteps_header.value = ( f"

Query Execution Steps - [query_idx: {query_idx}]

" @@ -869,11 +871,12 @@ def update_cpu_time( Callback function that displays the CPU Time by node and ``path_id``. """ - display( + print_message( super().get_cpu_time( kind=kind, categoryorder=categoryorder, - ) + ), + "display", ) self._cpu_header.value = ( f"

CPU Time by node and path_id - [query_idx: {query_idx}]

" @@ -900,8 +903,8 @@ def step(self): out = widgets.Output() with out: out.clear_output(wait=True) - display(interactive_output) - display(widgets.VBox([step_navigation, out])) + print_message(interactive_output, "display") + print_message(widgets.VBox([step_navigation, out]), "display") def update_step(self, step_idx): """ @@ -911,9 +914,9 @@ def update_step(self, step_idx): """ steps_id = self.get_step_funcs() if steps_id[step_idx] == NotImplemented: - display("NotImplemented") + print_message("NotImplemented", "display") else: - display(steps_id[step_idx]()) + print_message(steps_id[step_idx](), "display") self.step_text.value = f"Step {step_idx}" def _next_step_clicked(self, button): @@ -1077,4 +1080,4 @@ def display(self): """ Displays the final side-by-side UI. """ - display(self.side_by_side_ui) + print_message(self.side_by_side_ui, "display") diff --git a/verticapy/plotting/_plotly/machine_learning/champion_challenger.py b/verticapy/plotting/_plotly/machine_learning/champion_challenger.py index 93c3e7276..c00f4f2d1 100644 --- a/verticapy/plotting/_plotly/machine_learning/champion_challenger.py +++ b/verticapy/plotting/_plotly/machine_learning/champion_challenger.py @@ -62,7 +62,7 @@ def _init_style(self) -> None: "hovertemplate": "%{customdata}
" f"{self.layout['x_label']}: " "%{x}
" - f"{self.layout['x_label']}:" + f"{self.layout['y_label']}:" " %{y}
" f"STD:" " %{marker.size:.3f} " From e35030ca614e8b38489702afe49e07ee70dbb7fe Mon Sep 17 00:00:00 2001 From: Badr Date: Wed, 2 Oct 2024 10:46:06 -0400 Subject: [PATCH 7/7] final correction --- verticapy/core/vdataframe/_aggregate.py | 13 +++++++------ .../vertica/tensorflow/freeze_tf2_model.py | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/verticapy/core/vdataframe/_aggregate.py b/verticapy/core/vdataframe/_aggregate.py index 8f4f37c7c..fbd72f6ce 100755 --- a/verticapy/core/vdataframe/_aggregate.py +++ b/verticapy/core/vdataframe/_aggregate.py @@ -1022,12 +1022,13 @@ def describe( if pre_comp == "VERTICAPY_NOT_PRECOMPUTED": col_to_compute += [column] break - warning_message = ( - f"The vDataColumn {column} is not numerical, it was ignored." - "\nTo get statistical information about all different " - "variables, please use the parameter method = 'categorical'." - ) - print_message(warning_message, "warning") + else: + warning_message = ( + f"The vDataColumn {column} is not numerical, it was ignored." + "\nTo get statistical information about all different " + "variables, please use the parameter method = 'categorical'." + ) + print_message(warning_message, "warning") for column in columns: if column not in col_to_compute: values["index"] += [column.replace('"', "")] diff --git a/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py b/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py index fe36577a2..8c352ce6c 100644 --- a/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py +++ b/verticapy/machine_learning/vertica/tensorflow/freeze_tf2_model.py @@ -51,7 +51,7 @@ def get_str_from_dtype(dtype, is_input, idx): sys.exit() in_or_out = "Input" if is_input else "Output" - print_message(in_or_out, str(idx), "is of type:", dtype_str) + print_message(in_or_out + str(idx) + "is of type:" + dtype_str) return dtype_str @@ -66,7 +66,7 @@ def freeze_model(model, save_dir, column_type): # Convert Keras model to ConcreteFunction full_model = tf.function(lambda x: model(x)) - print_message("Model Input:", model.input) + print_message("Model Input:" + str(model.input)) if isinstance(model.input, list): no_of_inputs = len(model.input)