From 4244526b0f40022d88439cd3b22aaa65914ea2bf Mon Sep 17 00:00:00 2001 From: srinivaspavan9 Date: Sun, 17 Dec 2023 20:29:09 -0500 Subject: [PATCH 1/7] Updated utils.py for better warning messages --- taipy/gui/_renderers/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taipy/gui/_renderers/utils.py b/taipy/gui/_renderers/utils.py index d06a09e295..d964976c55 100644 --- a/taipy/gui/_renderers/utils.py +++ b/taipy/gui/_renderers/utils.py @@ -37,7 +37,7 @@ def _get_columns_dict_from_list( idx += 1 elif col: _warn( - f'Error column "{col}" is not present in the Dataframe "{value.head(0) if hasattr(value, "head") else value}".' # noqa: E501 + f'Error column "{col}" is not present. Available columns: {list(value.columns)}.' # noqa: E501 ) return col_dict From 4956c18fb607a2cf58b0d04b83f986d22daa2093 Mon Sep 17 00:00:00 2001 From: srinivaspavan9 Date: Wed, 20 Dec 2023 09:34:38 -0500 Subject: [PATCH 2/7] added value check for dataframe --- taipy/gui/_renderers/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/taipy/gui/_renderers/utils.py b/taipy/gui/_renderers/utils.py index d964976c55..941c06f532 100644 --- a/taipy/gui/_renderers/utils.py +++ b/taipy/gui/_renderers/utils.py @@ -10,6 +10,7 @@ # specific language governing permissions and limitations under the License. import typing as t +import pandas as pd from .._warnings import _warn from ..gui_types import NumberTypes @@ -29,6 +30,11 @@ def _get_tuple_val(attr: tuple, index: int, default_val: t.Any) -> t.Any: def _get_columns_dict_from_list( col_list: t.Union[t.List[str], t.Tuple[str]], col_types_keys: t.List[str], value: t.Any ): + #Check if 'Value' is a Dataframe + if not isinstance(value,pd.Dataframe): + _warn("The 'value' argument is not a pandas DataFrame.") + return {} + col_dict = {} idx = 0 for col in col_list: From 9ee469a89d53e3cf9530fe51d2d70c86af304080 Mon Sep 17 00:00:00 2001 From: srinivaspavan9 Date: Wed, 20 Dec 2023 15:43:47 -0500 Subject: [PATCH 3/7] added the check at the warning level --- taipy/gui/_renderers/utils.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/taipy/gui/_renderers/utils.py b/taipy/gui/_renderers/utils.py index 941c06f532..4cfe85d4a9 100644 --- a/taipy/gui/_renderers/utils.py +++ b/taipy/gui/_renderers/utils.py @@ -30,11 +30,6 @@ def _get_tuple_val(attr: tuple, index: int, default_val: t.Any) -> t.Any: def _get_columns_dict_from_list( col_list: t.Union[t.List[str], t.Tuple[str]], col_types_keys: t.List[str], value: t.Any ): - #Check if 'Value' is a Dataframe - if not isinstance(value,pd.Dataframe): - _warn("The 'value' argument is not a pandas DataFrame.") - return {} - col_dict = {} idx = 0 for col in col_list: @@ -42,9 +37,13 @@ def _get_columns_dict_from_list( col_dict[col] = {"index": idx} idx += 1 elif col: - _warn( - f'Error column "{col}" is not present. Available columns: {list(value.columns)}.' # noqa: E501 - ) + if isinstance(value,pd.DataFrame): + if col not in value.columns: + _warn( + f'Error column "{col}" is not present. Available columns: {list(value.columns)}.' # noqa: E501 + ) + else: + _warn("The 'value' argument is not a pandas DataFrame.") return col_dict From a613b417f1ea73ed6b4d5c32e744dcfb369bce7c Mon Sep 17 00:00:00 2001 From: srinivaspavan9 Date: Wed, 20 Dec 2023 15:47:31 -0500 Subject: [PATCH 4/7] resolved linter comments --- taipy/gui/_renderers/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taipy/gui/_renderers/utils.py b/taipy/gui/_renderers/utils.py index 4cfe85d4a9..e296ef36fd 100644 --- a/taipy/gui/_renderers/utils.py +++ b/taipy/gui/_renderers/utils.py @@ -37,7 +37,7 @@ def _get_columns_dict_from_list( col_dict[col] = {"index": idx} idx += 1 elif col: - if isinstance(value,pd.DataFrame): + if isinstance(value, pd.DataFrame): if col not in value.columns: _warn( f'Error column "{col}" is not present. Available columns: {list(value.columns)}.' # noqa: E501 From 97e5f03291856ac451973f6c2788b5c3648fb205 Mon Sep 17 00:00:00 2001 From: srinivaspavan9 Date: Sun, 24 Dec 2023 12:56:06 -0500 Subject: [PATCH 5/7] added required changes --- taipy/gui/_renderers/utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/taipy/gui/_renderers/utils.py b/taipy/gui/_renderers/utils.py index e296ef36fd..b311b231ba 100644 --- a/taipy/gui/_renderers/utils.py +++ b/taipy/gui/_renderers/utils.py @@ -32,18 +32,22 @@ def _get_columns_dict_from_list( ): col_dict = {} idx = 0 + cols = str(list(value.columns) if isinstance(value, pd.DataFrame) + else list(value.keys()) if isinstance(value, (dict, _MapDict)) + else value if isinstance(value, (list, tuple)) + else value) + for col in col_list: if col in col_types_keys: col_dict[col] = {"index": idx} idx += 1 elif col: - if isinstance(value, pd.DataFrame): - if col not in value.columns: - _warn( - f'Error column "{col}" is not present. Available columns: {list(value.columns)}.' # noqa: E501 - ) + if col not in cols: + _warn( + f'Error column "{col}" is not present. Available columns/keys: {cols}.' # noqa: E501 + ) else: - _warn("The 'value' argument is not a pandas DataFrame.") + _warn("The 'value' argument is of an unsupported type. Expected DataFrame, dict, list, or tuple.") return col_dict From 8d969ebaee8142d9b7544e878539ca0f683fe9ac Mon Sep 17 00:00:00 2001 From: srinivaspavan9 Date: Sun, 24 Dec 2023 13:44:45 -0500 Subject: [PATCH 6/7] Linter Changes --- taipy/gui/_renderers/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/taipy/gui/_renderers/utils.py b/taipy/gui/_renderers/utils.py index b311b231ba..1b8df08ba7 100644 --- a/taipy/gui/_renderers/utils.py +++ b/taipy/gui/_renderers/utils.py @@ -32,11 +32,11 @@ def _get_columns_dict_from_list( ): col_dict = {} idx = 0 - cols = str(list(value.columns) if isinstance(value, pd.DataFrame) - else list(value.keys()) if isinstance(value, (dict, _MapDict)) - else value if isinstance(value, (list, tuple)) - else value) - + cols = str(list(value.columns) if isinstance(value, pd.DataFrame) + else list(value.keys()) if isinstance(value, (dict, _MapDict)) + else value if isinstance(value, (list, tuple)) + else value) + for col in col_list: if col in col_types_keys: col_dict[col] = {"index": idx} From a12c39f3fb509c6c0f1eb80390363e2cfedb0a14 Mon Sep 17 00:00:00 2001 From: srinivaspavan9 Date: Sun, 24 Dec 2023 15:09:33 -0500 Subject: [PATCH 7/7] Linter Changes --- taipy/gui/_renderers/utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/taipy/gui/_renderers/utils.py b/taipy/gui/_renderers/utils.py index 1b8df08ba7..7299010648 100644 --- a/taipy/gui/_renderers/utils.py +++ b/taipy/gui/_renderers/utils.py @@ -32,10 +32,7 @@ def _get_columns_dict_from_list( ): col_dict = {} idx = 0 - cols = str(list(value.columns) if isinstance(value, pd.DataFrame) - else list(value.keys()) if isinstance(value, (dict, _MapDict)) - else value if isinstance(value, (list, tuple)) - else value) + cols = str(list(value.columns) if isinstance(value, pd.DataFrame) else list(value.keys()) if isinstance(value, (dict, _MapDict)) else value if isinstance(value, (list, tuple)) else value) for col in col_list: if col in col_types_keys: