Skip to content

Commit 493e619

Browse files
committed
iter
1 parent e821387 commit 493e619

File tree

12 files changed

+118
-254
lines changed

12 files changed

+118
-254
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

imblearn/_min_dependencies.py

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

imblearn/ensemble/_bagging.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import copy
88
import numbers
9-
import warnings
109

1110
import numpy as np
1211
import sklearn
@@ -121,14 +120,6 @@ class BalancedBaggingClassifier(_ParamsValidationMixin, BaggingClassifier):
121120
122121
.. versionadded:: 0.10
123122
124-
n_features_ : int
125-
The number of features when `fit` is performed.
126-
127-
.. deprecated:: 1.0
128-
`n_features_` is deprecated in `scikit-learn` 1.0 and will be removed
129-
in version 1.2. When the minimum version of `scikit-learn` supported
130-
by `imbalanced-learn` will reach 1.2, this attribute will be removed.
131-
132123
estimators_ : list of estimators
133124
The collection of fitted base estimators.
134125
@@ -331,20 +322,6 @@ def _validate_estimator(self, default=DecisionTreeClassifier()):
331322
[("sampler", self.sampler_), ("classifier", estimator)]
332323
)
333324

334-
# TODO: remove when supporting scikit-learn>=1.2
335-
@property
336-
def n_features_(self):
337-
"""Number of features when ``fit`` is performed."""
338-
warnings.warn(
339-
(
340-
"`n_features_` was deprecated in scikit-learn 1.0. This attribute will "
341-
"not be accessible when the minimum supported version of scikit-learn "
342-
"is 1.2."
343-
),
344-
FutureWarning,
345-
)
346-
return self.n_features_in_
347-
348325
@_fit_context(prefer_skip_nested_validation=False)
349326
def fit(self, X, y):
350327
"""Build a Bagging ensemble of estimators from the training set (X, y).

imblearn/ensemble/_easy_ensemble.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,6 @@ class EasyEnsembleClassifier(_ParamsValidationMixin, BaggingClassifier):
100100
n_classes_ : int or list
101101
The number of classes.
102102
103-
n_features_ : int
104-
The number of features when `fit` is performed.
105-
106-
.. deprecated:: 1.0
107-
`n_features_` is deprecated in `scikit-learn` 1.0 and will be removed
108-
in version 1.2. When the minimum version of `scikit-learn` supported
109-
by `imbalanced-learn` will reach 1.2, this attribute will be removed.
110-
111103
n_features_in_ : int
112104
Number of features in the input dataset.
113105

imblearn/ensemble/_forest.py

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,6 @@ class labels (multi-output problem).
343343
The number of classes (single output problem), or a list containing the
344344
number of classes for each output (multi-output problem).
345345
346-
n_features_ : int
347-
The number of features when `fit` is performed.
348-
349-
.. deprecated:: 1.0
350-
`n_features_` is deprecated in `scikit-learn` 1.0 and will be removed
351-
in version 1.2. When the minimum version of `scikit-learn` supported
352-
by `imbalanced-learn` will reach 1.2, this attribute will be removed.
353-
354346
n_features_in_ : int
355347
Number of features in the input dataset.
356348
@@ -502,13 +494,8 @@ def __init__(
502494
def _validate_estimator(self, default=DecisionTreeClassifier()):
503495
"""Check the estimator and the n_estimator attribute, set the
504496
`estimator_` attribute."""
505-
if hasattr(self, "estimator"):
506-
base_estimator = self.estimator
507-
else:
508-
base_estimator = self.base_estimator
509-
510-
if base_estimator is not None:
511-
self.estimator_ = clone(base_estimator)
497+
if self.estimator is not None:
498+
self.estimator_ = clone(self.estimator)
512499
else:
513500
self.estimator_ = clone(default)
514501

@@ -893,22 +880,5 @@ def _compute_oob_predictions(self, X, y):
893880

894881
return oob_pred
895882

896-
# TODO: remove when supporting scikit-learn>=1.2
897-
@property
898-
def n_features_(self):
899-
"""Number of features when ``fit`` is performed."""
900-
warn(
901-
(
902-
"`n_features_` was deprecated in scikit-learn 1.0. This attribute will "
903-
"not be accessible when the minimum supported version of scikit-learn "
904-
"is 1.2."
905-
),
906-
FutureWarning,
907-
)
908-
return self.n_features_in_
909-
910883
def _more_tags(self):
911-
return {
912-
"multioutput": False,
913-
"multilabel": False,
914-
}
884+
return {"multioutput": False, "multilabel": False}

imblearn/ensemble/tests/test_bagging.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,3 @@ def roughly_balanced_bagging(X, y, replace=False):
581581
for estimator in rbb.estimators_:
582582
class_counts = estimator[-1].class_counts_
583583
assert (class_counts[0] / class_counts[1]) > 0.78
584-
585-
586-
def test_balanced_bagging_classifier_n_features():
587-
"""Check that we raise a FutureWarning when accessing `n_features_`."""
588-
X, y = load_iris(return_X_y=True)
589-
estimator = BalancedBaggingClassifier().fit(X, y)
590-
with pytest.warns(FutureWarning, match="`n_features_` was deprecated"):
591-
estimator.n_features_

imblearn/ensemble/tests/test_easy_ensemble.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,3 @@ def test_easy_ensemble_classifier_grid_search():
222222
cv=5,
223223
)
224224
grid_search.fit(X, y)
225-
226-
227-
def test_easy_ensemble_classifier_n_features():
228-
"""Check that we raise a FutureWarning when accessing `n_features_`."""
229-
X, y = load_iris(return_X_y=True)
230-
estimator = EasyEnsembleClassifier().fit(X, y)
231-
with pytest.warns(FutureWarning, match="`n_features_` was deprecated"):
232-
estimator.n_features_

imblearn/ensemble/tests/test_forest.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33
import sklearn
4-
from sklearn.datasets import load_iris, make_classification
4+
from sklearn.datasets import make_classification
55
from sklearn.model_selection import GridSearchCV, train_test_split
66
from sklearn.utils._testing import assert_allclose, assert_array_equal
77
from sklearn.utils.fixes import parse_version
@@ -219,16 +219,6 @@ def test_balanced_random_forest_oob_binomial(ratio):
219219
assert np.abs(erf.oob_score_ - 0.5) < 0.1
220220

221221

222-
def test_balanced_bagging_classifier_n_features():
223-
"""Check that we raise a FutureWarning when accessing `n_features_`."""
224-
X, y = load_iris(return_X_y=True)
225-
estimator = BalancedRandomForestClassifier(
226-
sampling_strategy="all", replacement=True, bootstrap=False
227-
).fit(X, y)
228-
with pytest.warns(FutureWarning, match="`n_features_` was deprecated"):
229-
estimator.n_features_
230-
231-
232222
# TODO: remove in 0.13
233223
def test_balanced_random_forest_change_behaviour(imbalanced_dataset):
234224
"""Check that we raise a change of behaviour for the parameters `sampling_strategy`

imblearn/utils/estimator_checks.py

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ def _set_checking_parameters(estimator):
7373
if "n_estimators" in params:
7474
estimator.set_params(n_estimators=min(5, estimator.n_estimators))
7575
if name == "ClusterCentroids":
76-
if sklearn_version < parse_version("1.1"):
77-
algorithm = "full"
78-
else:
79-
algorithm = "lloyd"
76+
algorithm = "lloyd"
8077
estimator.set_params(
8178
voting="soft",
8279
estimator=KMeans(random_state=0, algorithm=algorithm, n_init=1),
@@ -689,33 +686,14 @@ def check_dataframe_column_names_consistency(name, estimator_orig):
689686
X_bad = pd.DataFrame(X, columns=invalid_name)
690687

691688
for name, method in check_methods:
692-
if sklearn_version >= parse_version("1.2"):
693-
expected_msg = re.escape(
694-
"The feature names should match those that were passed during fit."
695-
f"\n{additional_message}"
696-
)
697-
with raises(
698-
ValueError, match=expected_msg, err_msg=f"{name} did not raise"
699-
):
700-
method(X_bad)
701-
else:
702-
expected_msg = re.escape(
703-
"The feature names should match those that were passed "
704-
"during fit. Starting version 1.2, an error will be raised.\n"
705-
f"{additional_message}"
706-
)
707-
with warnings.catch_warnings():
708-
warnings.filterwarnings(
709-
"error",
710-
category=FutureWarning,
711-
module="sklearn",
712-
)
713-
with raises(
714-
FutureWarning,
715-
match=expected_msg,
716-
err_msg=f"{name} did not raise",
717-
):
718-
method(X_bad)
689+
expected_msg = re.escape(
690+
"The feature names should match those that were passed during fit."
691+
f"\n{additional_message}"
692+
)
693+
with raises(
694+
ValueError, match=expected_msg, err_msg=f"{name} did not raise"
695+
):
696+
method(X_bad)
719697

720698
# partial_fit checks on second call
721699
# Do not call partial fit if early_stopping is on

imblearn/utils/tests/test_min_dependencies.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"""Tests for the minimum dependencies in the README.rst file."""
2+
23
import os
34
import platform
45
import re
56
from pathlib import Path
67

78
import pytest
8-
from sklearn.utils.fixes import parse_version
9+
import tomllib
10+
from packaging.requirements import Requirement
11+
from packaging.version import parse
912

1013
import imblearn
11-
from imblearn._min_dependencies import dependent_packages
1214

1315

1416
@pytest.mark.skipif(
@@ -17,7 +19,35 @@
1719
def test_min_dependencies_readme():
1820
# Test that the minimum dependencies in the README.rst file are
1921
# consistent with the minimum dependencies defined at the file:
20-
# imblearn/_min_dependencies.py
22+
# pyproject.toml
23+
24+
pyproject_path = Path(imblearn.__path__[0]).parents[0] / "pyproject.toml"
25+
with open(pyproject_path, "rb") as f:
26+
pyproject_data = tomllib.load(f)
27+
28+
def process_requirements(requirements):
29+
result = {}
30+
for req in requirements:
31+
req = Requirement(req)
32+
for specifier in req.specifier:
33+
if specifier.operator == ">=":
34+
result[req.name] = parse(specifier.version)
35+
return result
36+
37+
min_dependencies = process_requirements(
38+
[f"python{pyproject_data['project']['requires-python']}"]
39+
)
40+
min_dependencies.update(
41+
process_requirements(pyproject_data["project"]["dependencies"])
42+
)
43+
44+
markers = ["docs", "optional", "tensorflow", "keras", "tests"]
45+
for marker_name in markers:
46+
min_dependencies.update(
47+
process_requirements(
48+
pyproject_data["project"]["optional-dependencies"][marker_name]
49+
)
50+
)
2151

2252
pattern = re.compile(
2353
r"(\.\. \|)"
@@ -44,8 +74,8 @@ def test_min_dependencies_readme():
4474
package, version = matched.group(2), matched.group(5)
4575
package = package.lower()
4676

47-
if package in dependent_packages:
48-
version = parse_version(version)
49-
min_version = parse_version(dependent_packages[package][0])
77+
if package in min_dependencies:
78+
version = parse(version)
79+
min_version = min_dependencies[package]
5080

5181
assert version == min_version, f"{package} has a mismatched version"

0 commit comments

Comments
 (0)