Unknown category '2' encountered. Set `add_nan=True` to allow unknown categories pytorch_forecasting
error: &quot;Unknown category '2' encountered. Set add_nan=True to allow unknown categories&quot; while creating time series dataset in pytorch forecasting.
training = TimeSeriesDataSet(
train,
time_idx=&quot;index&quot;,
target=dni,
group_ids=[&quot;Solar Zenith Angle&quot;, &quot;Relative Humidity&quot;,&quot;Dew 
Point&quot;,&quot;Temperature&quot;,&quot;Precipitable Water&quot;, &quot;Wind Speed&quot;],
min_encoder_length=max_encoder_length // 2,  # keep encoder length long (as it is in the 
validation set)
max_encoder_length=max_encoder_length,
min_prediction_length=1,
max_prediction_length=max_prediction_length,
static_reals=[&quot;Wind Direction&quot;],
time_varying_known_reals=[&quot;index&quot;, &quot;Solar Zenith Angle&quot;, &quot;Relative Humidity&quot;,&quot;Dew 
Point&quot;,&quot;Temperature&quot;,&quot;Precipitable Water&quot;],
#     time_varying_unknown_categoricals=[],
time_varying_unknown_reals=[dhi,dni,ghi],
categorical_encoders={data.columns[2]: NaNLabelEncoder(add_nan=True)},
target_normalizer=GroupNormalizer(
    groups=[&quot;Solar Zenith Angle&quot;, &quot;Relative Humidity&quot;,&quot;Dew 
Point&quot;,&quot;Temperature&quot;,&quot;Precipitable Water&quot;, &quot;Wind Speed&quot;], transformation=&quot;softplus&quot;
),  # use softplus and normalize by group
add_relative_time_idx=True,
add_target_scales=True,
add_encoder_length=True,

)

Try adding pytorch_forecasting.data.encoders.NaNLabelEncoder(add_nan=True), as in this example:
max_prediction_length = 1
max_encoder_length = 27


training = TimeSeriesDataSet(
    sales_train,
    time_idx='dayofyear',
    target=&quot;QTT&quot;,
    group_ids=['S100','I100','C100','C101'],
    min_encoder_length=0,  
    max_encoder_length=max_encoder_length,
    min_prediction_length=1,
    max_prediction_length=max_prediction_length,
    static_categoricals=[],
    static_reals=['S100','I100','C100','C101'],
    time_varying_known_categoricals=[],  
    time_varying_known_reals=['DATE'],
    time_varying_unknown_categoricals=[],
    time_varying_unknown_reals=['DATE'],
    categorical_encoders={
        'S100': *pytorch_forecasting.data.encoders.NaNLabelEncoder(add_nan=True),*
        'I100':pytorch_forecasting.data.encoders.NaNLabelEncoder(add_nan=True),
        'C100':pytorch_forecasting.data.encoders.NaNLabelEncoder(add_nan=True),
        'C101':pytorch_forecasting.data.encoders.NaNLabelEncoder(add_nan=True)
    },
    add_relative_time_idx=True,
    add_target_scales=True,
    add_encoder_length=True,
    allow_missing_timesteps=True
   
    
)
print ('Executado')

