File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -320,6 +320,8 @@ def set_params(self, **kwargs):
320320 return self
321321
322322 def _validate_steps (self ):
323+ if not self .steps :
324+ raise ValueError ("The pipeline is empty. Please add steps." )
323325 names , estimators = zip (* self .steps )
324326
325327 # validate names
@@ -1289,7 +1291,6 @@ def __sklearn_is_fitted__(self):
12891291
12901292 An empty pipeline is considered fitted.
12911293 """
1292-
12931294 # First find the last step that is not 'passthrough'
12941295 last_step = None
12951296 for _ , estimator in reversed (self .steps ):
Original file line number Diff line number Diff line change @@ -282,6 +282,16 @@ def test_pipeline_invalid_parameters():
282282 assert params == params2
283283
284284
285+ def test_empty_pipeline ():
286+ X = iris .data
287+ y = iris .target
288+
289+ pipe = Pipeline ([])
290+ msg = "The pipeline is empty. Please add steps."
291+ with pytest .raises (ValueError , match = msg ):
292+ pipe .fit (X , y )
293+
294+
285295def test_pipeline_init_tuple ():
286296 # Pipeline accepts steps as tuple
287297 X = np .array ([[1 , 2 ]])
You can’t perform that action at this time.
0 commit comments