Skip to content

Commit dbfbd6e

Browse files
committed
remove dead code
1 parent 24925dc commit dbfbd6e

File tree

10 files changed

+21
-192
lines changed

10 files changed

+21
-192
lines changed

imblearn/base.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@
88

99
import numpy as np
1010
import sklearn
11-
from sklearn.base import BaseEstimator
12-
13-
try:
14-
# scikit-learn >= 1.2
15-
from sklearn.base import OneToOneFeatureMixin
16-
except ImportError:
17-
from sklearn.base import _OneToOneFeatureMixin as OneToOneFeatureMixin
18-
11+
from sklearn.base import BaseEstimator, OneToOneFeatureMixin
1912
from sklearn.preprocessing import label_binarize
2013
from sklearn.utils.fixes import parse_version
2114
from sklearn.utils.multiclass import check_classification_targets

imblearn/ensemble/_bagging.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,17 @@
1414
from sklearn.ensemble import BaggingClassifier
1515
from sklearn.ensemble._bagging import _parallel_decision_function
1616
from sklearn.ensemble._base import _partition_estimators
17-
from sklearn.exceptions import NotFittedError
1817
from sklearn.tree import DecisionTreeClassifier
1918
from sklearn.utils.fixes import parse_version
19+
from sklearn.utils.metaestimators import available_if
20+
from sklearn.utils.parallel import Parallel, delayed
2021
from sklearn.utils.validation import check_is_fitted
2122

22-
try:
23-
# scikit-learn >= 1.2
24-
from sklearn.utils.parallel import Parallel, delayed
25-
except (ImportError, ModuleNotFoundError):
26-
from joblib import Parallel
27-
from sklearn.utils.fixes import delayed
28-
2923
from ..base import _ParamsValidationMixin
3024
from ..pipeline import Pipeline
3125
from ..under_sampling import RandomUnderSampler
3226
from ..under_sampling.base import BaseUnderSampler
3327
from ..utils import Substitution, check_sampling_strategy, check_target_type
34-
from ..utils._available_if import available_if
3528
from ..utils._docstring import _n_jobs_docstring, _random_state_docstring
3629
from ..utils._param_validation import HasMethods, Interval, StrOptions
3730
from ..utils.fixes import _fit_context
@@ -443,14 +436,6 @@ def base_estimator_(self):
443436
error = AttributeError(
444437
f"{self.__class__.__name__} object has no attribute 'base_estimator_'."
445438
)
446-
if sklearn_version < parse_version("1.2"):
447-
# The base class require to have the attribute defined. For scikit-learn
448-
# > 1.2, we are going to raise an error.
449-
try:
450-
check_is_fitted(self)
451-
return self.estimator_
452-
except NotFittedError:
453-
raise error
454439
raise error
455440

456441
def _more_tags(self):

imblearn/ensemble/_easy_ensemble.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,17 @@
1414
from sklearn.ensemble import AdaBoostClassifier, BaggingClassifier
1515
from sklearn.ensemble._bagging import _parallel_decision_function
1616
from sklearn.ensemble._base import _partition_estimators
17-
from sklearn.exceptions import NotFittedError
1817
from sklearn.utils._tags import _safe_tags
1918
from sklearn.utils.fixes import parse_version
19+
from sklearn.utils.metaestimators import available_if
20+
from sklearn.utils.parallel import Parallel, delayed
2021
from sklearn.utils.validation import check_is_fitted
2122

22-
try:
23-
# scikit-learn >= 1.2
24-
from sklearn.utils.parallel import Parallel, delayed
25-
except (ImportError, ModuleNotFoundError):
26-
from joblib import Parallel
27-
from sklearn.utils.fixes import delayed
28-
2923
from ..base import _ParamsValidationMixin
3024
from ..pipeline import Pipeline
3125
from ..under_sampling import RandomUnderSampler
3226
from ..under_sampling.base import BaseUnderSampler
3327
from ..utils import Substitution, check_sampling_strategy, check_target_type
34-
from ..utils._available_if import available_if
3528
from ..utils._docstring import _n_jobs_docstring, _random_state_docstring
3629
from ..utils._param_validation import Interval, StrOptions
3730
from ..utils.fixes import _fit_context
@@ -357,14 +350,6 @@ def base_estimator_(self):
357350
error = AttributeError(
358351
f"{self.__class__.__name__} object has no attribute 'base_estimator_'."
359352
)
360-
if sklearn_version < parse_version("1.2"):
361-
# The base class require to have the attribute defined. For scikit-learn
362-
# > 1.2, we are going to raise an error.
363-
try:
364-
check_is_fitted(self)
365-
return self.estimator_
366-
except NotFittedError:
367-
raise error
368353
raise error
369354

370355
def _get_estimator(self):

imblearn/ensemble/_forest.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,9 @@
2525
from sklearn.utils import _safe_indexing, check_random_state
2626
from sklearn.utils.fixes import parse_version
2727
from sklearn.utils.multiclass import type_of_target
28+
from sklearn.utils.parallel import Parallel, delayed
2829
from sklearn.utils.validation import _check_sample_weight
2930

30-
try:
31-
# scikit-learn >= 1.2
32-
from sklearn.utils.parallel import Parallel, delayed
33-
except (ImportError, ModuleNotFoundError):
34-
from joblib import Parallel
35-
from sklearn.utils.fixes import delayed
36-
3731
from ..base import _ParamsValidationMixin
3832
from ..pipeline import make_pipeline
3933
from ..under_sampling import RandomUnderSampler
@@ -80,6 +74,7 @@ def _local_parallel_build_trees(
8074
"verbose": verbose,
8175
"class_weight": class_weight,
8276
"n_samples_bootstrap": n_samples_bootstrap,
77+
"bootstrap": bootstrap,
8378
}
8479

8580
if parse_version(sklearn_version.base_version) >= parse_version("1.4"):
@@ -89,13 +84,6 @@ def _local_parallel_build_trees(
8984
missing_values_in_feature_mask
9085
)
9186

92-
# TODO: remove when the minimum supported version of scikit-learn will be 1.1
93-
# change of signature in scikit-learn 1.1
94-
if parse_version(sklearn_version.base_version) >= parse_version("1.1"):
95-
params_parallel_build_trees["bootstrap"] = bootstrap
96-
else:
97-
params_parallel_build_trees["forest"] = forest
98-
9987
tree = _parallel_build_trees(**params_parallel_build_trees)
10088

10189
return sampler, tree

imblearn/over_sampling/_smote/tests/test_smote_nc.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,21 +272,17 @@ def test_smote_nc_with_null_median_std():
272272
def test_smotenc_categorical_encoder():
273273
"""Check that we can pass our own categorical encoder."""
274274

275-
# TODO: only use `sparse_output` when sklearn >= 1.2
276-
param = "sparse" if sklearn_version < parse_version("1.2") else "sparse_output"
277-
278275
X, y, categorical_features = data_heterogneous_unordered()
279276
smote = SMOTENC(categorical_features=categorical_features, random_state=0)
280277
smote.fit_resample(X, y)
281278

282-
assert getattr(smote.categorical_encoder_, param) is True
279+
assert getattr(smote.categorical_encoder_, "sparse_output") is True
283280

284-
encoder = OneHotEncoder()
285-
encoder.set_params(**{param: False})
281+
encoder = OneHotEncoder(sparse_output=False)
286282
smote.set_params(categorical_encoder=encoder).fit_resample(X, y)
287283
assert smote.categorical_encoder is encoder
288284
assert smote.categorical_encoder_ is not encoder
289-
assert getattr(smote.categorical_encoder_, param) is False
285+
assert getattr(smote.categorical_encoder_, "sparse_output") is False
290286

291287

292288
# TODO(0.13): remove this test

imblearn/tests/test_docstring_parameters.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@
1616
check_docstring_parameters,
1717
ignore_warnings,
1818
)
19-
from sklearn.utils.estimator_checks import _enforce_estimator_tags_y
20-
21-
try:
22-
from sklearn.utils.estimator_checks import _enforce_estimator_tags_x
23-
except ImportError:
24-
# scikit-learn >= 1.2
25-
from sklearn.utils.estimator_checks import (
26-
_enforce_estimator_tags_X as _enforce_estimator_tags_x,
27-
)
28-
2919
from sklearn.utils.deprecation import _is_deprecated
30-
from sklearn.utils.estimator_checks import _construct_instance
20+
from sklearn.utils.estimator_checks import (
21+
_construct_instance,
22+
_enforce_estimator_tags_X,
23+
_enforce_estimator_tags_y,
24+
)
3125

3226
import imblearn
3327
from imblearn.base import is_sampler
@@ -197,7 +191,7 @@ def test_fit_docstring_attributes(name, Estimator):
197191
)
198192

199193
y = _enforce_estimator_tags_y(est, y)
200-
X = _enforce_estimator_tags_x(est, X)
194+
X = _enforce_estimator_tags_X(est, X)
201195

202196
if "oob_score" in est.get_params():
203197
est.set_params(bootstrap=True, oob_score=True)

imblearn/tests/test_pipeline.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,9 +1338,6 @@ def test_pipeline_param_validation():
13381338
check_param_validation("Pipeline", model)
13391339

13401340

1341-
@pytest.mark.skipif(
1342-
sklearn_version < parse_version("1.2"), reason="requires scikit-learn >= 1.2"
1343-
)
13441341
def test_pipeline_with_set_output():
13451342
pd = pytest.importorskip("pandas")
13461343
X, y = load_iris(return_X_y=True, as_frame=True)

imblearn/utils/_available_if.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

imblearn/utils/_param_validation.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""This is a copy of sklearn/utils/_param_validation.py. It can be removed when
2-
we support scikit-learn >= 1.2.
3-
"""
1+
"""This is a copy of sklearn/utils/_param_validation.py."""
42
# mypy: ignore-errors
53
import functools
64
import math

imblearn/utils/estimator_checks.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,11 @@
3535
set_random_state,
3636
)
3737
from sklearn.utils.estimator_checks import (
38+
_enforce_estimator_tags_X,
3839
_enforce_estimator_tags_y,
3940
_get_check_estimator_ids,
4041
_maybe_mark_xfail,
4142
)
42-
43-
try:
44-
from sklearn.utils.estimator_checks import _enforce_estimator_tags_x
45-
except ImportError:
46-
# scikit-learn >= 1.2
47-
from sklearn.utils.estimator_checks import (
48-
_enforce_estimator_tags_X as _enforce_estimator_tags_x,
49-
)
50-
5143
from sklearn.utils.fixes import parse_version
5244
from sklearn.utils.multiclass import type_of_target
5345

@@ -602,7 +594,7 @@ def check_dataframe_column_names_consistency(name, estimator_orig):
602594

603595
X_orig = rng.normal(size=(150, 8))
604596

605-
X_orig = _enforce_estimator_tags_x(estimator, X_orig)
597+
X_orig = _enforce_estimator_tags_X(estimator, X_orig)
606598
n_samples, n_features = X_orig.shape
607599

608600
names = np.array([f"col_{i}" for i in range(n_features)])
@@ -756,7 +748,7 @@ def check_sampler_get_feature_names_out(name, sampler_orig):
756748
X = StandardScaler().fit_transform(X)
757749

758750
sampler = clone(sampler_orig)
759-
X = _enforce_estimator_tags_x(sampler, X)
751+
X = _enforce_estimator_tags_X(sampler, X)
760752

761753
n_features = X.shape[1]
762754
set_random_state(sampler)
@@ -804,7 +796,7 @@ def check_sampler_get_feature_names_out_pandas(name, sampler_orig):
804796
X = StandardScaler().fit_transform(X)
805797

806798
sampler = clone(sampler_orig)
807-
X = _enforce_estimator_tags_x(sampler, X)
799+
X = _enforce_estimator_tags_X(sampler, X)
808800

809801
n_features = X.shape[1]
810802
set_random_state(sampler)

0 commit comments

Comments
 (0)