functime-org / functime

Time-series machine learning at scale. Built with Polars for embarrassingly parallel feature extraction and forecasts on panel data.
https://docs.functime.ai
Apache License 2.0
971 stars 52 forks source link

TypeError using plot_forecasts #179

Closed miroslaavi closed 2 months ago

miroslaavi commented 4 months ago

When trying to plot using functime plot_forecasts getting "TypeError: the truth value of a DataFrame is ambiguous", which is most likely doing with the fact that plotly make_subplots parameter subplot_titles is receiving a pl.DataFrame containing the unique entities instead of a list.

import polars as pl
import datetime as dt

y_test = pl.DataFrame({
    "Market": ["CH", "CH", "CH", "DE", "DE", "DE", "US", "US", "US"],
    "Date": [dt.date(2024, 2, 9), dt.date(2024, 2, 10), dt.date(2024, 2, 11),
             dt.date(2024, 2, 9), dt.date(2024, 2, 10), dt.date(2024, 2, 11),
             dt.date(2024, 2, 9), dt.date(2024, 2, 10), dt.date(2024, 2, 11)],
    "Visitors": [26303, 28994, 28781, 26788, 27560, 27039, 28012, 29534, 29007]
})

y_pred = pl.DataFrame({
    "Market": ["CH", "CH", "CH", "DE", "DE", "DE", "US", "US", "US"],
    "Date": [dt.date(2024, 2, 9), dt.date(2024, 2, 10), dt.date(2024, 2, 11),
             dt.date(2024, 2, 9), dt.date(2024, 2, 10), dt.date(2024, 2, 11),
             dt.date(2024, 2, 9), dt.date(2024, 2, 10), dt.date(2024, 2, 11)],
    "Visitors": [26500, 29000, 28800, 26800, 27600, 27100, 28100, 29600, 29100]
})

plot_forecasts(y_true=y_test, y_pred=y_pred, n_series=3)

functime version 0.9.5 plotly version 5.19.0 python version 3.11.4