Skip to content

Commit 6739f3d

Browse files
chkoarglemaitre
andauthored
MAINT Improve pipeline's validation readability (#1066)
Co-authored-by: Guillaume Lemaitre <guillaume@probabl.ai>
1 parent c1074e4 commit 6739f3d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

imblearn/pipeline.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,20 @@ def _validate_steps(self):
163163
for t in transformers:
164164
if t is None or t == "passthrough":
165165
continue
166-
if not (
167-
hasattr(t, "fit")
168-
or hasattr(t, "fit_transform")
169-
or hasattr(t, "fit_resample")
170-
) or not (hasattr(t, "transform") or hasattr(t, "fit_resample")):
166+
167+
is_transfomer = hasattr(t, "fit") and hasattr(t, "transform")
168+
is_sampler = hasattr(t, "fit_resample")
169+
is_not_transfomer_or_sampler = not (is_transfomer or is_sampler)
170+
171+
if is_not_transfomer_or_sampler:
171172
raise TypeError(
172173
"All intermediate steps of the chain should "
173174
"be estimators that implement fit and transform or "
174175
"fit_resample (but not both) or be a string 'passthrough' "
175176
"'%s' (type %s) doesn't)" % (t, type(t))
176177
)
177178

178-
if hasattr(t, "fit_resample") and (
179-
hasattr(t, "fit_transform") or hasattr(t, "transform")
180-
):
179+
if is_transfomer and is_sampler:
181180
raise TypeError(
182181
"All intermediate steps of the chain should "
183182
"be estimators that implement fit and transform or "

0 commit comments

Comments
 (0)