diff --git a/sklearn/pipeline.py b/sklearn/pipeline.py index 8d738d4b90fff..26e1465de9986 100644 --- a/sklearn/pipeline.py +++ b/sklearn/pipeline.py @@ -623,8 +623,11 @@ def classes_(self): def _more_tags(self): # check if first estimator expects pairwise input - estimator_tags = self.steps[0][1]._get_tags() - return {'pairwise': estimator_tags.get('pairwise', False)} + try: + pairwise = self.steps[0][1]._get_tags().get('pairwise', False) + except AttributeError: + pairwise = False + return {'pairwise': pairwise} # TODO: Remove in 0.26 # mypy error: Decorated property not supported diff --git a/sklearn/tests/test_pipeline.py b/sklearn/tests/test_pipeline.py index bd88f4acd03c3..d9df891d90128 100644 --- a/sklearn/tests/test_pipeline.py +++ b/sklearn/tests/test_pipeline.py @@ -1264,3 +1264,11 @@ def test_feature_union_warns_unknown_transformer_weight(): union = FeatureUnion(transformer_list, transformer_weights=weights) with pytest.raises(ValueError, match=expected_msg): union.fit(X, y) + + +@pytest.mark.parametrize('passthrough', [None, 'passthrough']) +def test_pipeline_get_tags_none(passthrough): + """Checks that tags are set correctly when passthrough is None or + 'passthrough'""" + pipe = make_pipeline(passthrough, SVC()) + assert not pipe._get_tags()['pairwise']