Skip to content

MAINT fix compatibility with scikit-learn 1.7 #1137

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 1 commit into from
May 11, 2025
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions imblearn/ensemble/_easy_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# License: MIT

import copy
import inspect
import numbers

import numpy as np
Expand All @@ -13,7 +14,6 @@
from sklearn.ensemble._bagging import _parallel_decision_function
from sklearn.ensemble._base import _partition_estimators
from sklearn.utils._param_validation import Interval, StrOptions
from sklearn.utils._tags import _safe_tags
from sklearn.utils.fixes import parse_version
from sklearn.utils.metaestimators import available_if
from sklearn.utils.parallel import Parallel, delayed
Expand Down Expand Up @@ -312,11 +312,16 @@
# Parallel loop
n_jobs, _, starts = _partition_estimators(self.n_estimators, self.n_jobs)

kwargs = {}
if "params" in inspect.signature(_parallel_decision_function).parameters:
kwargs["params"] = {}

Check warning on line 317 in imblearn/ensemble/_easy_ensemble.py

View check run for this annotation

Codecov / codecov/patch

imblearn/ensemble/_easy_ensemble.py#L317

Added line #L317 was not covered by tests

all_decisions = Parallel(n_jobs=n_jobs, verbose=self.verbose)(
delayed(_parallel_decision_function)(
self.estimators_[starts[i] : starts[i + 1]],
self.estimators_features_[starts[i] : starts[i + 1]],
X,
**kwargs,
)
for i in range(n_jobs)
)
Expand All @@ -343,7 +348,7 @@
return self.estimator

def _more_tags(self):
return {"allow_nan": _safe_tags(self._get_estimator(), "allow_nan")}
return {"allow_nan": get_tags(self._get_estimator()).input_tags.allow_nan}

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
Expand Down
2 changes: 1 addition & 1 deletion imblearn/metrics/tests/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def test_iba_error_y_score_prob_error(score_loss):
y_true, y_pred, _ = make_prediction(binary=True)

aps = make_index_balanced_accuracy(alpha=0.5, squared=True)(score_loss)
with pytest.raises(AttributeError):
with pytest.raises((AttributeError, TypeError)):
aps(y_true, y_pred)


Expand Down
1 change: 0 additions & 1 deletion imblearn/over_sampling/_smote/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,5 @@ def _more_tags(self):

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.input_tags.sparse = False
tags.input_tags.string = True
return tags
5 changes: 4 additions & 1 deletion imblearn/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from imblearn.pipeline import Pipeline, make_pipeline
from imblearn.under_sampling import EditedNearestNeighbours as ENN
from imblearn.under_sampling import RandomUnderSampler
from imblearn.utils._sklearn_compat import sklearn_version
from imblearn.utils._sklearn_compat import Tags, sklearn_version
from imblearn.utils.estimator_checks import check_param_validation

JUNK_FOOD_DOCS = (
Expand All @@ -61,6 +61,9 @@ def __init__(self, a=None, b=None):
self.a = a
self.b = b

def __sklearn_tags__(self):
return Tags()


class NoTrans(NoFit):
def fit(self, X, y):
Expand Down