From ec3690a445df22fc2ad598a4d29522496c8b9645 Mon Sep 17 00:00:00 2001 From: chkoar Date: Wed, 28 Feb 2024 09:32:28 +0200 Subject: [PATCH 1/3] Improve pipeline's validation readability --- imblearn/pipeline.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/imblearn/pipeline.py b/imblearn/pipeline.py index 01eead7ea..a78082a1a 100644 --- a/imblearn/pipeline.py +++ b/imblearn/pipeline.py @@ -163,11 +163,13 @@ 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_transfomer_or_sampler = is_transfomer or is_sampler + is_transfomer_and_sampler = is_transfomer and is_sampler + + if not is_transfomer_or_sampler: raise TypeError( "All intermediate steps of the chain should " "be estimators that implement fit and transform or " @@ -175,9 +177,7 @@ def _validate_steps(self): "'%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_sampler: raise TypeError( "All intermediate steps of the chain should " "be estimators that implement fit and transform or " From f8cbee38d993283130955670c35b781b663a52a0 Mon Sep 17 00:00:00 2001 From: chkoar Date: Wed, 28 Feb 2024 09:35:26 +0200 Subject: [PATCH 2/3] Improve pipeline's validation readability --- imblearn/pipeline.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/imblearn/pipeline.py b/imblearn/pipeline.py index a78082a1a..070948b34 100644 --- a/imblearn/pipeline.py +++ b/imblearn/pipeline.py @@ -166,10 +166,8 @@ def _validate_steps(self): is_transfomer = hasattr(t, "fit") and hasattr(t, "transform") is_sampler = hasattr(t, "fit_resample") - is_transfomer_or_sampler = is_transfomer or is_sampler - is_transfomer_and_sampler = is_transfomer and is_sampler - if not is_transfomer_or_sampler: + if not (is_transfomer or is_sampler): raise TypeError( "All intermediate steps of the chain should " "be estimators that implement fit and transform or " @@ -177,7 +175,7 @@ def _validate_steps(self): "'%s' (type %s) doesn't)" % (t, type(t)) ) - if is_transfomer_and_sampler: + if is_transfomer and is_sampler: raise TypeError( "All intermediate steps of the chain should " "be estimators that implement fit and transform or " From 645029f252156f7c93264804428117b1019cacb7 Mon Sep 17 00:00:00 2001 From: chkoar Date: Wed, 28 Feb 2024 09:39:55 +0200 Subject: [PATCH 3/3] Improve pipeline's validation readability --- imblearn/pipeline.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imblearn/pipeline.py b/imblearn/pipeline.py index 070948b34..f98d58434 100644 --- a/imblearn/pipeline.py +++ b/imblearn/pipeline.py @@ -166,8 +166,9 @@ def _validate_steps(self): 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 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 "