Skip to content

MAINT Improve pipeline's validation readability #1066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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