From b9c22711d66c16f5775258cbdf2589d8e2fb6137 Mon Sep 17 00:00:00 2001 From: Samuel Hoffman Date: Tue, 20 Feb 2024 14:36:13 -0500 Subject: [PATCH] if_delegate_has_method -> available_if Signed-off-by: Samuel Hoffman --- aif360/sklearn/postprocessing/__init__.py | 10 +++++----- aif360/sklearn/preprocessing/reweighing.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/aif360/sklearn/postprocessing/__init__.py b/aif360/sklearn/postprocessing/__init__.py index af2c1286..b80719ea 100644 --- a/aif360/sklearn/postprocessing/__init__.py +++ b/aif360/sklearn/postprocessing/__init__.py @@ -7,7 +7,7 @@ import pandas as pd from sklearn.base import BaseEstimator, MetaEstimatorMixin, clone from sklearn.model_selection import train_test_split -from sklearn.utils.metaestimators import if_delegate_has_method +from sklearn.utils.metaestimators import available_if from aif360.sklearn.postprocessing.calibrated_equalized_odds import CalibratedEqualizedOdds from aif360.sklearn.postprocessing.reject_option_classification import RejectOptionClassifier, RejectOptionClassifierCV @@ -132,7 +132,7 @@ def fit(self, X, y, sample_weight=None, **fit_params): **fit_params) return self - @if_delegate_has_method('postprocessor_') + @available_if(lambda self: hasattr(self.postprocessor_, "predict")) def predict(self, X): """Predict class labels for the given samples. @@ -151,7 +151,7 @@ def predict(self, X): y_score = pd.DataFrame(y_score, index=X.index).squeeze('columns') return self.postprocessor_.predict(y_score) - @if_delegate_has_method('postprocessor_') + @available_if(lambda self: hasattr(self.postprocessor_, "predict_proba")) def predict_proba(self, X): """Probability estimates. @@ -175,7 +175,7 @@ def predict_proba(self, X): y_score = pd.DataFrame(y_score, index=X.index).squeeze('columns') return self.postprocessor_.predict_proba(y_score) - @if_delegate_has_method('postprocessor_') + @available_if(lambda self: hasattr(self.postprocessor_, "predict_log_proba")) def predict_log_proba(self, X): """Log of probability estimates. @@ -199,7 +199,7 @@ def predict_log_proba(self, X): y_score = pd.DataFrame(y_score, index=X.index).squeeze('columns') return self.postprocessor_.predict_log_proba(y_score) - @if_delegate_has_method('postprocessor_') + @available_if(lambda self: hasattr(self.postprocessor_, "score")) def score(self, X, y, sample_weight=None): """Returns the output of the post-processor's score function on the given test data and labels. diff --git a/aif360/sklearn/preprocessing/reweighing.py b/aif360/sklearn/preprocessing/reweighing.py index 3af4d7ff..3b6a8321 100644 --- a/aif360/sklearn/preprocessing/reweighing.py +++ b/aif360/sklearn/preprocessing/reweighing.py @@ -1,6 +1,6 @@ import numpy as np from sklearn.base import BaseEstimator, MetaEstimatorMixin, clone -from sklearn.utils.metaestimators import if_delegate_has_method +from sklearn.utils.metaestimators import available_if from sklearn.utils.validation import has_fit_parameter from aif360.sklearn.utils import check_inputs, check_groups @@ -153,7 +153,7 @@ def fit(self, X, y, sample_weight=None): self.estimator_.fit(X, y, sample_weight=sample_weight) return self - @if_delegate_has_method('estimator_') + @available_if(lambda self: hasattr(self.estimator_, "predict")) def predict(self, X): """Predict class labels for the given samples using ``self.estimator_``. @@ -165,7 +165,7 @@ def predict(self, X): """ return self.estimator_.predict(X) - @if_delegate_has_method('estimator_') + @available_if(lambda self: hasattr(self.estimator_, "predict_proba")) def predict_proba(self, X): """Probability estimates from ``self.estimator_``. @@ -181,7 +181,7 @@ def predict_proba(self, X): """ return self.estimator_.predict_proba(X) - @if_delegate_has_method('estimator_') + @available_if(lambda self: hasattr(self.estimator_, "predict_log_proba")) def predict_log_proba(self, X): """Log of probability estimates from ``self.estimator_``. @@ -198,7 +198,7 @@ def predict_log_proba(self, X): """ return self.estimator_.predict_log_proba(X) - @if_delegate_has_method('estimator_') + @available_if(lambda self: hasattr(self.estimator_, "score")) def score(self, X, y, sample_weight=None): """Returns the output of the estimator's score function on the given test data and labels.