Skip to content

Commit 00763ab

Browse files
MNT Reduce iteration over steps in _sk_visual_block_ (scikit-learn#29022)
Co-authored-by: Jérémie du Boisberranger <jeremie@probabl.ai>
1 parent aa2131f commit 00763ab

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

sklearn/pipeline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,15 +1312,15 @@ def __sklearn_is_fitted__(self):
13121312
return False
13131313

13141314
def _sk_visual_block_(self):
1315-
_, estimators = zip(*self.steps)
1316-
13171315
def _get_name(name, est):
13181316
if est is None or est == "passthrough":
13191317
return f"{name}: passthrough"
13201318
# Is an estimator
13211319
return f"{name}: {est.__class__.__name__}"
13221320

1323-
names = [_get_name(name, est) for name, est in self.steps]
1321+
names, estimators = zip(
1322+
*[(_get_name(name, est), est) for name, est in self.steps]
1323+
)
13241324
name_details = [str(est) for est in estimators]
13251325
return _VisualBlock(
13261326
"serial",

sklearn/utils/_repr_html/tests/test_estimator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ def test_get_visual_block_pipeline():
9999
est_html_info = _get_visual_block(pipe)
100100
assert est_html_info.kind == "serial"
101101
assert est_html_info.estimators == tuple(step[1] for step in pipe.steps)
102-
assert est_html_info.names == [
102+
assert est_html_info.names == (
103103
"imputer: SimpleImputer",
104104
"do_nothing: passthrough",
105105
"do_nothing_more: passthrough",
106106
"classifier: LogisticRegression",
107-
]
107+
)
108108
assert est_html_info.name_details == [str(est) for _, est in pipe.steps]
109109

110110

0 commit comments

Comments
 (0)