Description
When initializing the Samformer model, the constructor accepts a metadata parameter with the type hint dict | None = None. However, the __init__ method unconditionally attempts to index into self.metadata (e.g., self.metadata['max_encoder_length']), which immediately throws a TypeError: 'NoneType' object is not subscriptable and crashes initialization if metadata is None.
Location
pytorch_forecasting/models/samformer/_samformer_v2.py, specifically lines 77-79.
Steps to reproduce
import torch.nn as nn
from pytorch_forecasting.models.samformer._samformer_v2 import Samformer
model = Samformer(loss=nn.MSELoss(), hidden_size=512, use_revin=True, metadata=None)
Suggested fix
Add an explicit validation check in the __init__ method, or remove the None default to make metadata a strictly required argument.
if metadata is None:
raise ValueError("Samformer requires 'metadata' dictionary to be provided for initialization.")
Description
When initializing the
Samformermodel, the constructor accepts ametadataparameter with the type hintdict | None = None. However, the__init__method unconditionally attempts to index intoself.metadata(e.g.,self.metadata['max_encoder_length']), which immediately throws aTypeError: 'NoneType' object is not subscriptableand crashes initialization ifmetadataisNone.Location
pytorch_forecasting/models/samformer/_samformer_v2.py, specifically lines 77-79.Steps to reproduce
Suggested fix
Add an explicit validation check in the
__init__method, or remove theNonedefault to makemetadataa strictly required argument.