Skip to content

Commit

Permalink
MAINT Improve pipeline's validation readability (#1066)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Lemaitre <guillaume@probabl.ai>
  • Loading branch information
chkoar and glemaitre committed Mar 31, 2024
1 parent c1074e4 commit 6739f3d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions imblearn/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,20 @@ def _validate_steps(self):
for t in transformers:
if t is None or t == "passthrough":
continue
if not (
hasattr(t, "fit")
or hasattr(t, "fit_transform")
or hasattr(t, "fit_resample")
) or not (hasattr(t, "transform") or hasattr(t, "fit_resample")):

is_transfomer = hasattr(t, "fit") and hasattr(t, "transform")
is_sampler = hasattr(t, "fit_resample")
is_not_transfomer_or_sampler = not (is_transfomer or is_sampler)

if is_not_transfomer_or_sampler:
raise TypeError(
"All intermediate steps of the chain should "
"be estimators that implement fit and transform or "
"fit_resample (but not both) or be a string 'passthrough' "
"'%s' (type %s) doesn't)" % (t, type(t))
)

if hasattr(t, "fit_resample") and (
hasattr(t, "fit_transform") or hasattr(t, "transform")
):
if is_transfomer and is_sampler:
raise TypeError(
"All intermediate steps of the chain should "
"be estimators that implement fit and transform or "
Expand Down

0 comments on commit 6739f3d

Please sign in to comment.