Repository: ourownstory/neural_prophet

Issue:
[bug] index mismatch with events in global setup
By @rbeldagarcia in #827
 
Hello! Thanks for the update, some features are very useful like to allow create a global model with a unique data frame.

I write this comment to report some observation of the new version.  I have tried to migrate my models written in 0.3.2 to 0.4.1 and I have found some issues.
In particular, these models are Global model with events, and the problems appear in: 
Could you confirm if the requirements.txt is updated? I would like to validate that my environment is correct before reporting this as a bug. In particular, I have tried with:

pandas=1.3.5
neuralprophet=0.4.1
numpy=1.21.6

I have tried to create a new environment with requirements.txt but it reports a error trying to install torch>=1.8.0

df_utils.py (line 1006)    

```
    for event in config_events.keys():
        event_feature = pd.Series([0.0] * df.shape[0])
        event_feature.index = df.index  #added to fix the errors, without this it reports NaN when the events are added to the dataframe in global model. 
        				 #The problem is that if df.index != event_feature.index then it return NaN when try to do: df[event] = event_feature


        # events_df may be None in case ID from original df is not provided in events df
        if events_df is None:
            dates = None
        else:
            dates = events_df[events_df.event == event].ds
            event_feature.iloc[df.ds.isin(dates)] = 1.0 #Added 'iloc' to support events that are only present in some 'ID' groups
        df[event] = event_feature
    return df
```
    
I attach you the code and a screen shoot 

[Neuralprophet041.zip](https://github.com/ourownstory/neural_prophet/files/9818669/Neuralprophet041.zip)

_Originally posted by @rbeldagarcia in https://github.com/ourownstory/neural_prophet/discussions/827#discussioncomment-3913276_
    


Discussion:
@rbeldagarcia
Thank you for raising this.
Would you be able to simplify your example code further to the absolute minimum needed to reproduce the error?
That would help us to troubleshoot.

Thank you!
Oskar
Hello! Of course, you can reproduce with the following code:

```
import pandas as pd
from neuralprophet import NeuralProphet
data_location = "https://raw.githubusercontent.com/ourownstory/neuralprophet-data/main/datasets/"
df_ercot = pd.read_csv(data_location + "multivariate/load_ercot_regions.csv")[0:600]

history_events_df = pd.DataFrame()
for zona in list(df_ercot.columns.drop('ds')):
    playoffs_history = pd.DataFrame({
            'ID': zona,
            'event': f'Evento_{zona}',
            'ds': pd.to_datetime(['2007-05-01'])})
    history_events_df = pd.concat((history_events_df, playoffs_history))

df_ercot.ds = pd.date_range(end='1/2/2008', periods=600)
df_ercot = df_ercot.melt(id_vars=['ds'], value_vars=list(df_ercot.columns.drop('ds')), var_name='ID', value_name='y')

m = NeuralProphet()
m = m.add_events(list(history_events_df.event.unique()))

history_df = m.create_df_with_events(df_ercot, history_events_df)
```

Thank you, 

Resolving patch:
diff --git a/neuralprophet/df_utils.py b/neuralprophet/df_utils.py
--- a/neuralprophet/df_utils.py
+++ b/neuralprophet/df_utils.py
@@ -1027,6 +1027,7 @@ def convert_events_to_features(df, config_events, events_df):
             dates = None
         else:
             dates = events_df[events_df.event == event].ds
+            df.reset_index(drop=True, inplace=True)
             event_feature[df.ds.isin(dates)] = 1.0
         df[event] = event_feature
     return df


Test patch: