Avaiga / taipy

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

BUG- Cannot add scenarios with Scenario Selector #899

Closed FlorianJacta closed 6 months ago

FlorianJacta commented 6 months ago

Description

It is impossible to create a new scenario by adding it to the scenario selector when a scenario has already been created in the script.

C:\...\develop\lib\site-packages\taipy\gui\utils\_evaluator.py:260: TaipyGuiWarning: Exception raised evaluating __taipy_gui_core_Ctx.get_scenarios():
can't compare offset-naive and offset-aware datetimes

How to reproduce

Run this code and try to create a new scenario. Note that this code works if I don't create a scenario in my main script.

from taipy import Config
import taipy as tp
import pandas as pd
import datetime as dt

data = pd.read_csv("https://raw.githubusercontent.com/Avaiga/taipy-getting-started-core/develop/src/daily-min-temperatures.csv")

# Normal function used by Taipy
def predict(historical_temperature: pd.DataFrame, date_to_forecast: dt.datetime) -> float:
    print(f"Running baseline...")
    historical_temperature['Date'] = pd.to_datetime(historical_temperature['Date'])
    historical_same_day = historical_temperature.loc[
        (historical_temperature['Date'].dt.day == date_to_forecast.day) &
        (historical_temperature['Date'].dt.month == date_to_forecast.month)
    ]
    return historical_same_day['Temp'].mean()

# Configuration of Data Nodes
historical_temperature_cfg = Config.configure_data_node("historical_temperature")
date_to_forecast_cfg = Config.configure_data_node("date_to_forecast")
predictions_cfg = Config.configure_data_node("predictions")

# Configuration of tasks
predictions_cfg = Config.configure_task("predict",
                                        predict,
                                        [historical_temperature_cfg, date_to_forecast_cfg],
                                        predictions_cfg)

# Configuration of scenario
scenario_cfg = Config.configure_scenario(id="my_scenario", 
                                                    task_configs=[predictions_cfg])

Config.export('config.toml')

if __name__ == '__main__':
    # Run of the Core
    tp.Core().run()

    # Creation of the scenario and execution
    scenario = tp.create_scenario(scenario_cfg)
    scenario_md = """
<|{scenario}|scenario_selector|>
"""

    tp.Gui(scenario_md).run()

Expected behavior We should be able to create a scenario.

Runtime environment Please specify relevant indications.

Acceptance Criteria

FredLL-Avaiga commented 6 months ago

Can you modify your code example: def predict(historical_temperature: pd.DataFrame, date_to_forecast: str) -> float: to def predict(historical_temperature: pd.DataFrame, date_to_forecast: dt.datetime) -> float: tx