Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
15.36k stars 1.87k forks source link

[🐛 BUG] "String index out of range" when concatenating empty string #2235

Open CatherineVaughanJackson opened 2 days ago

CatherineVaughanJackson commented 2 days ago

What went wrong? 🤔

When trying to concatenate a string with the output from a LOV if the LOV value is an empty string like "" it'll return the error string index out of range. This was previously not an issue in Taipy version <4.0.

Steps to Reproduce Issue

from taipy.gui import Gui, Markdown
import plotly.graph_objects as go
import numpy as np

## Mock code

class Pipeline:
    def __init__(self):
        self.instance = {"model_1": Model()}

class Model:
    def __init__(self):
        self.confusion_matrix = {
            "group_norm": self.create_confusion_matrix(normalized=True),
            "group": self.create_confusion_matrix(normalized=False)
        }

    def create_confusion_matrix(self, normalized=False):
        # Example data for a 3x3 confusion matrix
        matrix = np.array([
            [30, 2, 1],
            [5, 25, 2],
            [3, 4, 28]
        ])

        if normalized:
            matrix = matrix / matrix.sum(axis=1)[:, np.newaxis]

        fig = go.Figure(data=go.Heatmap(
            z=matrix,
            x=['A', 'B', 'C'],
            y=['A', 'B', 'C'],
            colorscale='Blues'
        ))

        # Add title based on normalization
        title = "Normalized Confusion Matrix" if normalized else "Confusion Matrix"
        fig.update_layout(title=title)

        return fig

# Usage
pipeline = Pipeline()
types = [("_norm", "Normalized"), ("", "Raw Count")]
selected_type = types[0]

exec_matrix_page = Markdown("""
# Results
<|{selected_type}|toggle|lov={types}|>

<|chart|figure={pipeline.instance["model_1"].confusion_matrix["group"+ selected_type[0]]}|rebuild|>                     
""")

if __name__ == "__main__":
    gui = Gui(page=exec_matrix_page)
    gui.run(port=5001)`

Version of Taipy

4.0

Acceptance Criteria

Code of Conduct

FlorianJacta commented 1 day ago

Indeed, this was working in 3.1