Skip to content

Commit dd287c3

Browse files
authored
DOC validate docsring using numpydoc conventions (#640)
1 parent 2c7ed0f commit dd287c3

26 files changed

+655
-432
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ matrix:
3030
include:
3131
# This environment tests the using anaconda
3232
# Ubuntu 14.04 environment
33-
- env: DISTRIB="ubuntu" TEST_DOC="true"
33+
- env: DISTRIB="ubuntu" TEST_DOC="true" TEST_NUMPYDOC="false"
3434
# Latest release
3535
- env: DISTRIB="conda" PYTHON_VERSION="3.7"
3636
NUMPY_VERSION="*" SCIPY_VERSION="*" SKLEARN_VERSION="master"
37-
OPTIONAL_DEPS="keras" TEST_DOC="true"
37+
OPTIONAL_DEPS="keras" TEST_DOC="true" TEST_NUMPYDOC="false"
3838
- env: DISTRIB="conda" PYTHON_VERSION="3.7"
3939
NUMPY_VERSION="*" SCIPY_VERSION="*" SKLEARN_VERSION="master"
40-
OPTIONAL_DEPS="tensorflow" TEST_DOC="true"
40+
OPTIONAL_DEPS="tensorflow" TEST_DOC="true" TEST_NUMPYDOC="false"
4141
- env: DISTRIB="conda" PYTHON_VERSION="3.7"
4242
NUMPY_VERSION="*" SCIPY_VERSION="*" SKLEARN_VERSION="master"
43-
OPTIONAL_DEPS="false" TEST_DOC="false"
43+
OPTIONAL_DEPS="false" TEST_DOC="false" TEST_NUMPYDOC="true"
4444

4545
install: source build_tools/travis/install.sh
4646
script: bash build_tools/travis/test_script.sh

build_tools/travis/install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ if [[ "$DISTRIB" == "conda" ]]; then
5252

5353
conda install --yes pytest pytest-cov
5454
pip install codecov
55+
pip install -U git+https://github.com/numpy/numpydoc.git
5556

5657
elif [[ "$DISTRIB" == "ubuntu" ]]; then
5758
# At the time of writing numpy 1.9.1 is included in the travis

build_tools/travis/test_script.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ run_tests(){
2828
if [[ "$TEST_DOC" == "true" ]]; then
2929
make test-doc
3030
fi
31+
32+
# Validate numpydoc style
33+
if [[ "$TEST_NUMPYDOC" == "true" ]]; then
34+
pytest -vsl maint_tools/test_docstring.py
35+
fi
3136
}
3237

3338
if [[ "$SKIP_TESTS" != "true" ]]; then

imblearn/base.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@ def fit(self, X, y):
3232
3333
Parameters
3434
----------
35-
X : {array-like, sparse matrix}, shape (n_samples, n_features)
35+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
3636
Data array.
3737
38-
y : array-like, shape (n_samples,)
38+
y : array-like of shape (n_samples,)
3939
Target array.
4040
4141
Returns
4242
-------
4343
self : object
4444
Return the instance itself.
45-
4645
"""
4746
X, y, _ = self._check_X_y(X, y)
4847
self.sampling_strategy_ = check_sampling_strategy(
@@ -55,21 +54,20 @@ def fit_resample(self, X, y):
5554
5655
Parameters
5756
----------
58-
X : {array-like, sparse matrix}, shape (n_samples, n_features)
57+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
5958
Matrix containing the data which have to be sampled.
6059
61-
y : array-like, shape (n_samples,)
60+
y : array-like of shape (n_samples,)
6261
Corresponding label for each sample in X.
6362
6463
Returns
6564
-------
66-
X_resampled : {array-like, sparse matrix}, shape \
67-
(n_samples_new, n_features)
65+
X_resampled : {array-like, sparse matrix} of shape \
66+
(n_samples_new, n_features)
6867
The array containing the resampled data.
6968
70-
y_resampled : array-like, shape (n_samples_new,)
69+
y_resampled : array-like of shape (n_samples_new,)
7170
The corresponding label of `X_resampled`.
72-
7371
"""
7472
check_classification_targets(y)
7573
X, y, binarize_y = self._check_X_y(X, y)
@@ -97,20 +95,20 @@ def _fit_resample(self, X, y):
9795
9896
Parameters
9997
----------
100-
X : {array-like, sparse matrix}, shape (n_samples, n_features)
98+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
10199
Matrix containing the data which have to be sampled.
102100
103-
y : array-like, shape (n_samples,)
101+
y : array-like of shape (n_samples,)
104102
Corresponding label for each sample in X.
105103
106104
Returns
107105
-------
108-
X_resampled : {ndarray, sparse matrix}, shape \
109-
(n_samples_new, n_features)
106+
X_resampled : {ndarray, sparse matrix} of shape \
107+
(n_samples_new, n_features)
110108
The array containing the resampled data.
111109
112-
y_resampled : ndarray, shape (n_samples_new,)
113-
The corresponding label of `X_resampled`
110+
y_resampled : ndarray of shape (n_samples_new,)
111+
The corresponding label of `X_resampled`.
114112
115113
"""
116114
pass
@@ -146,26 +144,30 @@ class FunctionSampler(BaseSampler):
146144
147145
Parameters
148146
----------
149-
func : callable or None,
147+
func : callable, default=None
150148
The callable to use for the transformation. This will be passed the
151149
same arguments as transform, with args and kwargs forwarded. If func is
152150
None, then func will be the identity function.
153151
154-
accept_sparse : bool, optional (default=True)
152+
accept_sparse : bool, default=True
155153
Whether sparse input are supported. By default, sparse inputs are
156154
supported.
157155
158-
kw_args : dict, optional (default=None)
156+
kw_args : dict, default=None
159157
The keyword argument expected by ``func``.
160158
161159
validate : bool, default=True
162160
Whether or not to bypass the validation of ``X`` and ``y``. Turning-off
163161
validation allows to use the ``FunctionSampler`` with any type of
164162
data.
165163
164+
See Also
165+
--------
166+
167+
sklearn.preprocessing.FunctionTransfomer : Stateless transformer.
168+
166169
Notes
167170
-----
168-
169171
See
170172
:ref:`sphx_glr_auto_examples_plot_outlier_rejections.py`
171173
@@ -204,7 +206,6 @@ class FunctionSampler(BaseSampler):
204206
>>> print('Resampled dataset shape {}'.format(
205207
... sorted(Counter(y_res).items())))
206208
Resampled dataset shape [(0, 100), (1, 100)]
207-
208209
"""
209210

210211
_sampling_type = "bypass"
@@ -222,21 +223,20 @@ def fit_resample(self, X, y):
222223
223224
Parameters
224225
----------
225-
X : {array-like, sparse matrix}, shape (n_samples, n_features)
226+
X : {array-like, sparse matrix} of shape (n_samples, n_features)
226227
Matrix containing the data which have to be sampled.
227228
228-
y : array-like, shape (n_samples,)
229+
y : array-like of shape (n_samples,)
229230
Corresponding label for each sample in X.
230231
231232
Returns
232233
-------
233-
X_resampled : {array-like, sparse matrix}, shape \
234-
(n_samples_new, n_features)
234+
X_resampled : {array-like, sparse matrix} of shape \
235+
(n_samples_new, n_features)
235236
The array containing the resampled data.
236237
237-
y_resampled : array-like, shape (n_samples_new,)
238+
y_resampled : array-like of shape (n_samples_new,)
238239
The corresponding label of `X_resampled`.
239-
240240
"""
241241
if self.validate:
242242
check_classification_targets(y)

imblearn/combine/_smote_enn.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
from ..under_sampling import EditedNearestNeighbours
1414
from ..utils import check_target_type
1515
from ..utils import Substitution
16+
from ..utils._docstring import _n_jobs_docstring
1617
from ..utils._docstring import _random_state_docstring
1718

1819

1920
@Substitution(
2021
sampling_strategy=BaseOverSampler._sampling_strategy_docstring,
22+
n_jobs=_n_jobs_docstring,
2123
random_state=_random_state_docstring,
2224
)
2325
class SMOTEENN(BaseSampler):
24-
"""Class to perform over-sampling using SMOTE and cleaning using ENN.
26+
"""Over-sampling using SMOTE and cleaning using ENN.
2527
2628
Combine over- and under-sampling using SMOTE and Edited Nearest Neighbours.
2729
@@ -33,24 +35,23 @@ class SMOTEENN(BaseSampler):
3335
3436
{random_state}
3537
36-
smote : object, optional (default=SMOTE())
38+
smote : object, default=None
3739
The :class:`imblearn.over_sampling.SMOTE` object to use. If not given,
3840
a :class:`imblearn.over_sampling.SMOTE` object with default parameters
3941
will be given.
4042
41-
enn : object, optional (default=\
42-
EditedNearestNeighbours(sampling_strategy='all'))
43+
enn : object, default=None
4344
The :class:`imblearn.under_sampling.EditedNearestNeighbours` object
4445
to use. If not given, a
4546
:class:`imblearn.under_sampling.EditedNearestNeighbours` object with
4647
sampling strategy='all' will be given.
4748
48-
n_jobs : int or None, optional (default=None)
49-
Number of CPU cores used during the cross-validation loop.
50-
``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
51-
``-1`` means using all processors. See
52-
`Glossary <https://scikit-learn.org/stable/glossary.html#term-n-jobs>`_
53-
for more details.
49+
{n_jobs}
50+
51+
See Also
52+
--------
53+
SMOTETomek : Over-sample using SMOTE followed by under-sampling removing
54+
the Tomek's links.
5455
5556
Notes
5657
-----
@@ -59,11 +60,6 @@ class SMOTEENN(BaseSampler):
5960
Supports multi-class resampling. Refer to SMOTE and ENN regarding the
6061
scheme which used.
6162
62-
See also
63-
--------
64-
SMOTETomek : Over-sample using SMOTE followed by under-sampling removing
65-
the Tomek's links.
66-
6763
References
6864
----------
6965
.. [1] G. Batista, R. C. Prati, M. C. Monard. "A study of the behavior of
@@ -85,7 +81,6 @@ class SMOTEENN(BaseSampler):
8581
>>> X_res, y_res = sme.fit_resample(X, y)
8682
>>> print('Resampled dataset shape %s' % Counter(y_res))
8783
Resampled dataset shape Counter({{0: 900, 1: 881}})
88-
8984
"""
9085

9186
_sampling_type = "over-sampling"

imblearn/combine/_smote_tomek.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
from ..under_sampling import TomekLinks
1515
from ..utils import check_target_type
1616
from ..utils import Substitution
17+
from ..utils._docstring import _n_jobs_docstring
1718
from ..utils._docstring import _random_state_docstring
1819

1920

2021
@Substitution(
2122
sampling_strategy=BaseOverSampler._sampling_strategy_docstring,
23+
n_jobs=_n_jobs_docstring,
2224
random_state=_random_state_docstring,
2325
)
2426
class SMOTETomek(BaseSampler):
25-
"""Class to perform over-sampling using SMOTE and cleaning using
26-
Tomek links.
27+
"""Over-sampling using SMOTE and cleaning using Tomek links.
2728
2829
Combine over- and under-sampling using SMOTE and Tomek links.
2930
@@ -35,22 +36,22 @@ class SMOTETomek(BaseSampler):
3536
3637
{random_state}
3738
38-
smote : object, optional (default=SMOTE())
39+
smote : object, default=None
3940
The :class:`imblearn.over_sampling.SMOTE` object to use. If not given,
4041
a :class:`imblearn.over_sampling.SMOTE` object with default parameters
4142
will be given.
4243
43-
tomek : object, optional (default=TomekLinks(sampling_strategy='all'))
44+
tomek : object, default=None
4445
The :class:`imblearn.under_sampling.TomekLinks` object to use. If not
4546
given, a :class:`imblearn.under_sampling.TomekLinks` object with
4647
sampling strategy='all' will be given.
4748
48-
n_jobs : int or None, optional (default=None)
49-
Number of CPU cores used during the cross-validation loop.
50-
``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
51-
``-1`` means using all processors. See
52-
`Glossary <https://scikit-learn.org/stable/glossary.html#term-n-jobs>`_
53-
for more details.
49+
{n_jobs}
50+
51+
See Also
52+
--------
53+
SMOTEENN : Over-sample using SMOTE followed by under-sampling using Edited
54+
Nearest Neighbours.
5455
5556
Notes
5657
-----
@@ -59,11 +60,6 @@ class SMOTETomek(BaseSampler):
5960
Supports multi-class resampling. Refer to SMOTE and TomekLinks regarding
6061
the scheme which used.
6162
62-
See also
63-
--------
64-
SMOTEENN : Over-sample using SMOTE followed by under-sampling using Edited
65-
Nearest Neighbours.
66-
6763
References
6864
----------
6965
.. [1] G. Batista, B. Bazzan, M. Monard, "Balancing Training Data for
@@ -85,7 +81,6 @@ class SMOTETomek(BaseSampler):
8581
>>> X_res, y_res = smt.fit_resample(X, y)
8682
>>> print('Resampled dataset shape %s' % Counter(y_res))
8783
Resampled dataset shape Counter({{0: 900, 1: 900}})
88-
8984
"""
9085

9186
_sampling_type = "over-sampling"

0 commit comments

Comments
 (0)