Skip to content

Commit c960cfc

Browse files
authored
MNT deprecate passing kwargs by position (#721)
1 parent 3c6d232 commit c960cfc

29 files changed

+195
-20
lines changed

doc/whats_new/v0.7.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Maintenance
1919
- Remove `FutureWarning` issued by `scikit-learn` 0.23.
2020
:pr:`710` by :user:`Guillaume Lemaitre <glemaitre>`.
2121

22+
- Impose keywords only argument as in `scikit-learn`.
23+
:pr:`721` by :user:`Guillaume Lemaitre <glemaitre>`.
24+
2225
Changed models
2326
..............
2427

@@ -67,3 +70,7 @@ Deprecation
6770
:class:`imblearn.under_sampling.ClusterCentroids` since it was used by
6871
:class:`sklearn.cluster.KMeans` which deprecated it.
6972
:pr:`710` by :user:`Guillaume Lemaitre <glemaitre>`.
73+
74+
- Deprecation of passing keyword argument by position similarly to
75+
`scikit-learn`.
76+
:pr:`721` by :user:`Guillaume lemaitre <glemaitre>`.

imblearn/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from .utils import check_sampling_strategy, check_target_type
1616
from .utils._validation import ArraysTransformer
17+
from .utils._validation import _deprecate_positional_args
1718

1819

1920
class SamplerMixin(BaseEstimator, metaclass=ABCMeta):
@@ -213,7 +214,8 @@ class FunctionSampler(BaseSampler):
213214

214215
_sampling_type = "bypass"
215216

216-
def __init__(self, func=None, accept_sparse=True, kw_args=None,
217+
@_deprecate_positional_args
218+
def __init__(self, *, func=None, accept_sparse=True, kw_args=None,
217219
validate=True):
218220
super().__init__()
219221
self.func = func

imblearn/combine/_smote_enn.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from ..utils import Substitution
1616
from ..utils._docstring import _n_jobs_docstring
1717
from ..utils._docstring import _random_state_docstring
18+
from ..utils._validation import _deprecate_positional_args
1819

1920

2021
@Substitution(
@@ -85,8 +86,10 @@ class SMOTEENN(BaseSampler):
8586

8687
_sampling_type = "over-sampling"
8788

89+
@_deprecate_positional_args
8890
def __init__(
8991
self,
92+
*,
9093
sampling_strategy="auto",
9194
random_state=None,
9295
smote=None,

imblearn/combine/_smote_tomek.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ..utils import Substitution
1717
from ..utils._docstring import _n_jobs_docstring
1818
from ..utils._docstring import _random_state_docstring
19+
from ..utils._validation import _deprecate_positional_args
1920

2021

2122
@Substitution(
@@ -85,8 +86,10 @@ class SMOTETomek(BaseSampler):
8586

8687
_sampling_type = "over-sampling"
8788

89+
@_deprecate_positional_args
8890
def __init__(
8991
self,
92+
*,
9093
sampling_strategy="auto",
9194
random_state=None,
9295
smote=None,

imblearn/datasets/_imbalance.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
from ..under_sampling import RandomUnderSampler
1111
from ..utils import check_sampling_strategy
12+
from ..utils._validation import _deprecate_positional_args
1213

1314

15+
@_deprecate_positional_args
1416
def make_imbalance(
15-
X, y, sampling_strategy=None, random_state=None, verbose=False, **kwargs
17+
X, y, *, sampling_strategy=None, random_state=None, verbose=False, **kwargs
1618
):
1719
"""Turns a dataset into an imbalanced dataset with a specific sampling
1820
strategy.

imblearn/datasets/_zenodo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
from sklearn.utils import Bunch
5858
from sklearn.utils import check_random_state
5959

60+
from ..utils._validation import _deprecate_positional_args
61+
6062
URL = (
6163
"https://zenodo.org/record/61452/files/"
6264
"benchmark-imbalanced-learn.tar.gz"
@@ -101,7 +103,9 @@
101103
MAP_ID_NAME[v + 1] = k
102104

103105

106+
@_deprecate_positional_args
104107
def fetch_datasets(
108+
*,
105109
data_home=None,
106110
filter_data=None,
107111
download_if_missing=True,

imblearn/datasets/tests/test_imbalance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ def test_make_imbalance_error(iris, sampling_strategy, err_msg):
3232
# cover in the common tests so we will repeat it here
3333
X, y = iris
3434
with pytest.raises(ValueError, match=err_msg):
35-
make_imbalance(X, y, sampling_strategy)
35+
make_imbalance(X, y, sampling_strategy=sampling_strategy)
3636

3737

3838
def test_make_imbalance_error_single_class(iris):
3939
X, y = iris
4040
y = np.zeros_like(y)
4141
with pytest.raises(ValueError, match="needs to have more than 1 class."):
42-
make_imbalance(X, y, {0: 10})
42+
make_imbalance(X, y, sampling_strategy={0: 10})
4343

4444

4545
@pytest.mark.parametrize(

imblearn/ensemble/_bagging.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from ..utils import Substitution, check_target_type, check_sampling_strategy
1919
from ..utils._docstring import _n_jobs_docstring
2020
from ..utils._docstring import _random_state_docstring
21+
from ..utils._validation import _deprecate_positional_args
2122

2223

2324
@Substitution(
@@ -175,10 +176,12 @@ class BalancedBaggingClassifier(BaggingClassifier):
175176
[ 2 225]]
176177
"""
177178

179+
@_deprecate_positional_args
178180
def __init__(
179181
self,
180182
base_estimator=None,
181183
n_estimators=10,
184+
*,
182185
max_samples=1.0,
183186
max_features=1.0,
184187
bootstrap=True,

imblearn/ensemble/_easy_ensemble.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ..utils import Substitution, check_target_type, check_sampling_strategy
1818
from ..utils._docstring import _n_jobs_docstring
1919
from ..utils._docstring import _random_state_docstring
20+
from ..utils._validation import _deprecate_positional_args
2021
from ..pipeline import Pipeline
2122

2223
MAX_INT = np.iinfo(np.int32).max
@@ -125,10 +126,12 @@ class EasyEnsembleClassifier(BaggingClassifier):
125126
[ 2 225]]
126127
"""
127128

129+
@_deprecate_positional_args
128130
def __init__(
129131
self,
130132
n_estimators=10,
131133
base_estimator=None,
134+
*,
132135
warm_start=False,
133136
sampling_strategy="auto",
134137
replacement=False,

imblearn/ensemble/_forest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from ..utils._docstring import _n_jobs_docstring
3535
from ..utils._docstring import _random_state_docstring
3636
from ..utils._validation import check_sampling_strategy
37+
from ..utils._validation import _deprecate_positional_args
3738

3839
MAX_INT = np.iinfo(np.int32).max
3940

@@ -297,9 +298,11 @@ class labels (multi-output problem).
297298
[1]
298299
"""
299300

301+
@_deprecate_positional_args
300302
def __init__(
301303
self,
302304
n_estimators=100,
305+
*,
303306
criterion="gini",
304307
max_depth=None,
305308
min_samples_split=2,

0 commit comments

Comments
 (0)