Repository: Avaiga/taipy
Pull request: better message on column not found
based on [srinivaspavan9](https://github.com/srinivaspavan9)'s work
linter compliance

resolves #379 

Problem statement:
BUG-Inputting the wrong column name in a chart reports empty data
**Description**
Inputting the wrong column name in a chart visual element will report that the dataset used is empty when it is not. This leads the user to think that the issue is with the dataset instead of the column name.

**How to reproduce**
Running this code where I made a mistake on the y column of the chart visual element:

```python
from taipy import Gui
import pandas as pd

data = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})

page = """
<|{data}|chart|type=bar|x=a|y=hello|>
"""

Gui(page).run()
```

Leads to this error:
```
--- 1 warning(s) were found for page '/' in variable 'page' ---
 - Warning 1: Error column "hello" is not present in the Dataframe "Empty DataFrame
Columns: [a, b]
Index: []".
```

**Expected behavior**
The error should not mention that the DataFrame is empty, only that the column is not found


**Runtime environment**
 - OS: Windows 11
 - Browser: Chrome

Hints from issue discussion:
Hi  @AlexandreSajus  I have started working on this issue, I am trying to debug the code to find out where the warnings are being generated but it seems that I am not able to step into the Gui(page).run() line after hitting that breakpoint. what am i doing wrong ? and also i changed the first line to "from taipy.gui import Gui" as it was giving me import error. 
I need help
@srinivaspavan9 Yes you are right about the import error, this code is probably outdated. I'm not sure what you mean about the breakpoint issue. Maybe @jrobinAV could help?
> @srinivaspavan9 Yes you are right about the import error, this code is probably outdated. I'm not sure what you mean about the breakpoint issue. Maybe @jrobinAV could help?

I was trying to debug the code to find out where the warnings are being generated. But I am unable to debug because I am not able to get into the Gui(Page).run(), I mean right after hitting the break point the line is being skipped while debugging.

Can I know where the warnings are generated?
> > @srinivaspavan9 Yes you are right about the import error, this code is probably outdated. I'm not sure what you mean about the breakpoint issue. Maybe @jrobinAV could help?
> 
> I was trying to debug the code to find out where the warnings are being generated. But I am unable to debug because I am not able to get into the Gui(Page).run(), I mean right after hitting the break point the line is being skipped while debugging.
> 
> Can I know where the warnings are generated?

Ah I see, I don't think you are going to be able to use breakpoints this simply. We do have a debug mode that should give you more information with `Gui(page).run(debug=True)`. Let me ask R&D how they debug their code and get back to you.
> > > @srinivaspavan9 Yes you are right about the import error, this code is probably outdated. I'm not sure what you mean about the breakpoint issue. Maybe @jrobinAV could help?
> > 
> > 
> > I was trying to debug the code to find out where the warnings are being generated. But I am unable to debug because I am not able to get into the Gui(Page).run(), I mean right after hitting the break point the line is being skipped while debugging.
> > Can I know where the warnings are generated?
> 
> Ah I see, I don't think you are going to be able to use breakpoints this simply. We do have a debug mode that should give you more information with `Gui(page).run(debug=True)`. Let me ask R&D how they debug their code and get back to you.

Found this in utils.py
<img width="831" alt="image" src="https://github.com/Avaiga/taipy/assets/34889400/820af74c-296d-4ad0-9307-38d6bc07e30d">

I think this warning message can be modified. 
Can you confirm ?

Yes this should be it
I just submitted a PR for this issue #379
PR #617 

Your feedback and review would be greatly appreciated.
Perfect! We'll take a look

Commit message: format and small fix

Patch to review:
diff --git a/taipy/gui/_renderers/utils.py b/taipy/gui/_renderers/utils.py
index 54c74d0bb3..6100b0cecc 100644
--- a/taipy/gui/_renderers/utils.py
+++ b/taipy/gui/_renderers/utils.py
@@ -11,6 +11,8 @@
 
 import typing as t
 
+import pandas as pd
+
 from .._warnings import _warn
 from ..types import NumberTypes
 from ..utils import _RE_PD_TYPE, _get_date_col_str_name, _MapDict
@@ -31,14 +33,30 @@ def _get_columns_dict_from_list(
 ):
     col_dict = {}
     idx = 0
+    cols = None
+
     for col in col_list:
         if col in col_types_keys:
             col_dict[col] = {"index": idx}
             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
-            )
+            if cols is None:
+                cols = (
+                    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 []
+                )
+
+            if cols and (col not in cols):
+                _warn(
+                    f'Error column "{col}" is not present. Available columns: {cols}.'  # noqa: E501
+                )
+            else:
+                _warn("The 'value' argument is of an unsupported type. Expected DataFrame, dict, list, or tuple.")
     return col_dict
 
 


Code review comments:
diff_hunk: @@ -31,14 +33,30 @@ def _get_columns_dict_from_list(
 ):
     col_dict = {}
     idx = 0
+    cols = None
+
     for col in col_list:
         if col in col_types_keys:
             col_dict[col] = {"index": idx}
             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
-            )
+            if cols is None:
+                cols = (
+                    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 []
+                )
+
+            if cols and (col not in cols):
+                _warn(
+                    f'Error column "{col}" is not present. Available columns: {cols}.'  # noqa: E501
path: taipy/gui/_renderers/utils.py
text: @user1:
```suggestion
                    f'Column "{col}" is not present. Available columns: {cols}.'  # noqa: E501
```

diff_hunk: @@ -31,14 +33,30 @@ def _get_columns_dict_from_list(
 ):
     col_dict = {}
     idx = 0
+    cols = None
+
     for col in col_list:
         if col in col_types_keys:
             col_dict[col] = {"index": idx}
             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
-            )
+            if cols is None:
+                cols = (
+                    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 []
+                )
+
+            if cols and (col not in cols):
+                _warn(
+                    f'Error column "{col}" is not present. Available columns: {cols}.'  # noqa: E501
+                )
+            else:
+                _warn("The 'value' argument is of an unsupported type. Expected DataFrame, dict, list, or tuple.")
path: taipy/gui/_renderers/utils.py
text: @user1:
```suggestion
                _warn("The 'data' property value is of an unsupported type. Only DataFrame, dict, list, or tuple are supported.")
```
But is this enough?