Skip to content

Commit b56b346

Browse files
authored
MAINT cosmetic follow-up switch pixi + GitHub Actions (#1100)
1 parent 4d4cfd3 commit b56b346

21 files changed

+196
-620
lines changed

README.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
.. _scikit-learn-contrib: https://github.com/scikit-learn-contrib
66

7-
|Azure|_ |Codecov|_ |CircleCI|_ |PythonVersion|_ |Pypi|_ |Gitter|_ |Black|_
7+
|GitHubActions|_ |Codecov|_ |CircleCI|_ |PythonVersion|_ |Pypi|_ |Gitter|_ |Black|_
88

9-
.. |Azure| image:: https://dev.azure.com/imbalanced-learn/imbalanced-learn/_apis/build/status/scikit-learn-contrib.imbalanced-learn?branchName=master
10-
.. _Azure: https://dev.azure.com/imbalanced-learn/imbalanced-learn/_build
9+
.. |GitHubActions| image:: https://github.com/scikit-learn-contrib/imbalanced-learn/actions/workflows/tests.yml/badge.svg
10+
.. _GitHubActions: https://github.com/scikit-learn-contrib/imbalanced-learn/actions/workflows/tests.yml
1111

1212
.. |Codecov| image:: https://codecov.io/gh/scikit-learn-contrib/imbalanced-learn/branch/master/graph/badge.svg
1313
.. _Codecov: https://codecov.io/gh/scikit-learn-contrib/imbalanced-learn
@@ -66,6 +66,7 @@ Dependencies
6666
- NumPy (>= |NumPyMinVersion|)
6767
- SciPy (>= |SciPyMinVersion|)
6868
- Scikit-learn (>= |ScikitLearnMinVersion|)
69+
- Pytest (>= |PytestMinVersion|)
6970

7071
Additionally, `imbalanced-learn` requires the following optional dependencies:
7172

@@ -128,6 +129,21 @@ of the scikit-learn community. Therefore, you can refer to their
128129
`Development Guide
129130
<http://scikit-learn.org/stable/developers>`_.
130131

132+
Endorsement of the Scientific Python Specification
133+
--------------------------------------------------
134+
135+
We endorse good practices from the Scientific Python Ecosystem Coordination (SPEC).
136+
The full list of recommendations is available `here`_.
137+
138+
See below the list of recommendations that we endorse for the imbalanced-learn project.
139+
140+
|SPEC 0 — Minimum Supported Dependencies|
141+
142+
.. |SPEC 0 — Minimum Supported Dependencies| image:: https://img.shields.io/badge/SPEC-0-green?labelColor=%23004811&color=%235CA038
143+
:target: https://scientific-python.org/specs/spec-0000/
144+
145+
.. _here: https://scientific-python.org/specs/
146+
131147
About
132148
-----
133149

imblearn/_min_dependencies.py

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

imblearn/base.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,14 @@
77
from abc import ABCMeta, abstractmethod
88

99
import numpy as np
10-
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-
10+
from sklearn.base import BaseEstimator, OneToOneFeatureMixin
1911
from sklearn.preprocessing import label_binarize
20-
from sklearn.utils.fixes import parse_version
2112
from sklearn.utils.multiclass import check_classification_targets
2213

2314
from .utils import check_sampling_strategy, check_target_type
2415
from .utils._param_validation import validate_parameter_constraints
2516
from .utils._validation import ArraysTransformer
2617

27-
sklearn_version = parse_version(sklearn.__version__)
28-
2918

3019
class _ParamsValidationMixin:
3120
"""Mixin class to validate parameters."""

imblearn/ensemble/_bagging.py

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,24 @@
66

77
import copy
88
import numbers
9-
import warnings
109

1110
import numpy as np
1211
import sklearn
1312
from sklearn.base import clone
1413
from sklearn.ensemble import BaggingClassifier
1514
from sklearn.ensemble._bagging import _parallel_decision_function
1615
from sklearn.ensemble._base import _partition_estimators
17-
from sklearn.exceptions import NotFittedError
1816
from sklearn.tree import DecisionTreeClassifier
1917
from sklearn.utils.fixes import parse_version
18+
from sklearn.utils.metaestimators import available_if
19+
from sklearn.utils.parallel import Parallel, delayed
2020
from sklearn.utils.validation import check_is_fitted
2121

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-
2922
from ..base import _ParamsValidationMixin
3023
from ..pipeline import Pipeline
3124
from ..under_sampling import RandomUnderSampler
3225
from ..under_sampling.base import BaseUnderSampler
3326
from ..utils import Substitution, check_sampling_strategy, check_target_type
34-
from ..utils._available_if import available_if
3527
from ..utils._docstring import _n_jobs_docstring, _random_state_docstring
3628
from ..utils._param_validation import HasMethods, Interval, StrOptions
3729
from ..utils.fixes import _fit_context
@@ -128,14 +120,6 @@ class BalancedBaggingClassifier(_ParamsValidationMixin, BaggingClassifier):
128120
129121
.. versionadded:: 0.10
130122
131-
n_features_ : int
132-
The number of features when `fit` is performed.
133-
134-
.. deprecated:: 1.0
135-
`n_features_` is deprecated in `scikit-learn` 1.0 and will be removed
136-
in version 1.2. When the minimum version of `scikit-learn` supported
137-
by `imbalanced-learn` will reach 1.2, this attribute will be removed.
138-
139123
estimators_ : list of estimators
140124
The collection of fitted base estimators.
141125
@@ -338,20 +322,6 @@ def _validate_estimator(self, default=DecisionTreeClassifier()):
338322
[("sampler", self.sampler_), ("classifier", estimator)]
339323
)
340324

341-
# TODO: remove when supporting scikit-learn>=1.2
342-
@property
343-
def n_features_(self):
344-
"""Number of features when ``fit`` is performed."""
345-
warnings.warn(
346-
(
347-
"`n_features_` was deprecated in scikit-learn 1.0. This attribute will "
348-
"not be accessible when the minimum supported version of scikit-learn "
349-
"is 1.2."
350-
),
351-
FutureWarning,
352-
)
353-
return self.n_features_in_
354-
355325
@_fit_context(prefer_skip_nested_validation=False)
356326
def fit(self, X, y):
357327
"""Build a Bagging ensemble of estimators from the training set (X, y).
@@ -443,14 +413,6 @@ def base_estimator_(self):
443413
error = AttributeError(
444414
f"{self.__class__.__name__} object has no attribute 'base_estimator_'."
445415
)
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
454416
raise error
455417

456418
def _more_tags(self):

imblearn/ensemble/_easy_ensemble.py

Lines changed: 2 additions & 25 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
@@ -107,14 +100,6 @@ class EasyEnsembleClassifier(_ParamsValidationMixin, BaggingClassifier):
107100
n_classes_ : int or list
108101
The number of classes.
109102
110-
n_features_ : int
111-
The number of features when `fit` is performed.
112-
113-
.. deprecated:: 1.0
114-
`n_features_` is deprecated in `scikit-learn` 1.0 and will be removed
115-
in version 1.2. When the minimum version of `scikit-learn` supported
116-
by `imbalanced-learn` will reach 1.2, this attribute will be removed.
117-
118103
n_features_in_ : int
119104
Number of features in the input dataset.
120105
@@ -357,14 +342,6 @@ def base_estimator_(self):
357342
error = AttributeError(
358343
f"{self.__class__.__name__} object has no attribute 'base_estimator_'."
359344
)
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
368345
raise error
369346

370347
def _get_estimator(self):

imblearn/ensemble/_forest.py

Lines changed: 5 additions & 47 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
@@ -355,14 +343,6 @@ class labels (multi-output problem).
355343
The number of classes (single output problem), or a list containing the
356344
number of classes for each output (multi-output problem).
357345
358-
n_features_ : int
359-
The number of features when `fit` is performed.
360-
361-
.. deprecated:: 1.0
362-
`n_features_` is deprecated in `scikit-learn` 1.0 and will be removed
363-
in version 1.2. When the minimum version of `scikit-learn` supported
364-
by `imbalanced-learn` will reach 1.2, this attribute will be removed.
365-
366346
n_features_in_ : int
367347
Number of features in the input dataset.
368348
@@ -514,13 +494,8 @@ def __init__(
514494
def _validate_estimator(self, default=DecisionTreeClassifier()):
515495
"""Check the estimator and the n_estimator attribute, set the
516496
`estimator_` attribute."""
517-
if hasattr(self, "estimator"):
518-
base_estimator = self.estimator
519-
else:
520-
base_estimator = self.base_estimator
521-
522-
if base_estimator is not None:
523-
self.estimator_ = clone(base_estimator)
497+
if self.estimator is not None:
498+
self.estimator_ = clone(self.estimator)
524499
else:
525500
self.estimator_ = clone(default)
526501

@@ -905,22 +880,5 @@ def _compute_oob_predictions(self, X, y):
905880

906881
return oob_pred
907882

908-
# TODO: remove when supporting scikit-learn>=1.2
909-
@property
910-
def n_features_(self):
911-
"""Number of features when ``fit`` is performed."""
912-
warn(
913-
(
914-
"`n_features_` was deprecated in scikit-learn 1.0. This attribute will "
915-
"not be accessible when the minimum supported version of scikit-learn "
916-
"is 1.2."
917-
),
918-
FutureWarning,
919-
)
920-
return self.n_features_in_
921-
922883
def _more_tags(self):
923-
return {
924-
"multioutput": False,
925-
"multilabel": False,
926-
}
884+
return {"multioutput": False, "multilabel": False}

0 commit comments

Comments
 (0)