@@ -667,16 +667,16 @@ def _build_control_contribution(self) -> pt.TensorVariable | None:
667
667
pt.TensorVariable | None
668
668
Control contribution variable or None if no controls
669
669
"""
670
+ if self .control_columns is None or len (self .control_columns ) == 0 :
671
+ return None
672
+
670
673
X_data = self .preprocessed_data ["X" ]
671
- has_controls = (
672
- self .control_columns is not None
673
- and len (self .control_columns ) > 0
674
- and isinstance (X_data , pd .DataFrame )
675
- and all (column in X_data .columns for column in self .control_columns )
676
- )
674
+ if not isinstance (X_data , pd .DataFrame ):
675
+ raise TypeError ("X data must be a DataFrame for control contribution" )
677
676
678
- if not has_controls :
679
- return None
677
+ if not all (column in X_data .columns for column in self .control_columns ):
678
+ missing_cols = set (self .control_columns ) - set (X_data .columns )
679
+ raise ValueError (f"Control columns { missing_cols } not found in X data" )
680
680
681
681
if self .model_config ["gamma_control" ].dims != ("control" ,):
682
682
self .model_config ["gamma_control" ].dims = "control"
@@ -858,10 +858,12 @@ def build_model( # type: ignore[override]
858
858
if not isinstance (X_data , pd .DataFrame ):
859
859
raise TypeError ("X data must be a DataFrame" )
860
860
861
+ y_data = self .preprocessed_data ["y" ]
862
+ if not isinstance (y_data , (pd .Series , np .ndarray )):
863
+ raise TypeError ("y data must be a Series or ndarray" )
864
+
861
865
channel_data_scaled , target_scaled , _ , target_scale_ = (
862
- self ._create_scaled_data_variables (
863
- X_data [self .channel_columns ], self .preprocessed_data ["y" ]
864
- )
866
+ self ._create_scaled_data_variables (X_data [self .channel_columns ], y_data )
865
867
)
866
868
867
869
# Create time index if needed
@@ -1152,8 +1154,13 @@ def _prepare_target_data(
1152
1154
Dictionary with target data ready for pm.set_data
1153
1155
"""
1154
1156
if y is None :
1155
- dtype = self .preprocessed_data ["y" ].dtype # type: ignore
1156
- y_data = np .zeros (n_rows , dtype = dtype )
1157
+ # When y is None, create zeros array matching the type of preprocessed y
1158
+ y_preprocessed = self .preprocessed_data ["y" ]
1159
+ if isinstance (y_preprocessed , (pd .Series , np .ndarray )):
1160
+ y_data = np .zeros (n_rows , dtype = np .asarray (y_preprocessed ).dtype )
1161
+ else :
1162
+ # Default to float64 if type is unknown
1163
+ y_data = np .zeros (n_rows , dtype = "float64" )
1157
1164
elif isinstance (y , pd .Series ):
1158
1165
y_data = y .to_numpy ()
1159
1166
elif isinstance (y , np .ndarray ):
0 commit comments