Nixtla / utilsforecast

https://nixtlaverse.nixtla.io/utilsforecast
Apache License 2.0
42 stars 6 forks source link

plotting.py : _filter_series doesn't handle model names that break regex naming convention (eg. names that contain round parenthesis) #67

Closed paksas closed 7 months ago

paksas commented 7 months ago

Problem:

Calling StatsForecast.plot(returns, forecasts, unique_ids = ['AAPL'], models = ['GARCH(2,1)'], level=[80]) yields a KeyError: 'GARCH(2,1)-lo-80'

Steps to reproduce:

Follow the steps outlined in tutorial https://nixtlaverse.nixtla.io/statsforecast/docs/tutorials/garch_tutorial.html until and including section Forecast volatility. It contains the call shown above.

Analysis:

The exception originates in the auto-generated file utilsforecast/plotting.py. forecasts_df passed as an argument to plot_series and filtered using _filter_series function has the level columns removed if the model name contains any regex-reserved characters (such as parentheses).

The code that incorrectly removes those columns is located in line 30 of plotting.py:

interval_cols = [
      c
      for c in df.columns
      if re.search(rf"^({'|'.join(models)})-(?:lo|hi)-\d+", c)
  ]
jmoralez commented 7 months ago

Thanks for the great report! The fix will be on the next release.

paksas commented 7 months ago

thank you so much for a speedy fix :)

On Tue, 5 Mar 2024, 21:37 José Morales, @.***> wrote:

Thanks for the great report! The fix will be on the next release.

— Reply to this email directly, view it on GitHub https://github.com/Nixtla/utilsforecast/issues/67#issuecomment-1979678988, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABR6BTEHAUPV6AFU64TGSKDYWY3LHAVCNFSM6AAAAABEH323KCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZZGY3TQOJYHA . You are receiving this because you authored the thread.Message ID: @.***>