8000 DOC Ensures that SimpleImputer passes numpydoc validation (#21077) · scikit-learn/scikit-learn@635fb04 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 635fb04

Browse files
jmloyolaglemaitre
authored andcommitted
DOC Ensures that SimpleImputer passes numpydoc validation (#21077)
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
1 parent 8f2d211 commit 635fb04

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

maint_tools/test_docstrings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"SGDOneClassSVM",
4040
"SGDRegressor",
4141
"SelfTrainingClassifier",
42-
"SimpleImputer",
4342
"SparseRandomProjection",
4443
"SpectralBiclustering",
4544
"SpectralClustering",

sklearn/impute/_base.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class SimpleImputer(_BaseImputer):
134134
nullable integer dtypes with missing values, `missing_values`
135135
should be set to `np.nan`, since `pd.NA` will be converted to `np.nan`.
136136
137-
strategy : string, default='mean'
137+
strategy : str, default='mean'
138138
The imputation strategy.
139139
140140
- If "mean", then replace missing values using the mean along
@@ -150,25 +150,25 @@ class SimpleImputer(_BaseImputer):
150150
.. versionadded:: 0.20
151151
strategy="constant" for fixed value imputation.
152152
153-
fill_value : string or numerical value, default=None
153+
fill_value : str or numerical value, default=None
154154
When strategy == "constant", fill_value is used to replace all
155155
occurrences of missing_values.
156156
If left to the default, fill_value will be 0 when imputing numerical
157157
data and "missing_value" for strings or object data types.
158158
159-
verbose : integer, default=0
159+
verbose : int, default=0
160160
Controls the verbosity of the imputer.
161161
162-
copy : boolean, default=True
163-
If True, a copy of X will be created. If False, imputation will
162+
copy : bool, default=True
163+
If True, a copy of `X` will be created. If False, imputation will
164164
be done in-place whenever possible. Note that, in the following cases,
165165
a new copy will always be made, even if `copy=False`:
166166
167-
- If X is not an array of floating values;
168-
- If X is encoded as a CSR matrix;
169-
- If add_indicator=True.
167+
- If `X` is not an array of floating values;
168+
- If `X` is encoded as a CSR matrix;
169+
- If `add_indicator=True`.
170170
171-
add_indicator : boolean, default=False
171+
add_indicator : bool, default=False
172172
If True, a :class:`MissingIndicator` transform will stack onto output
173173
of the imputer's transform. This allows a predictive estimator
174174
to account for missingness despite imputation. If a feature has no
@@ -186,7 +186,7 @@ class SimpleImputer(_BaseImputer):
186186
187187
indicator_ : :class:`~sklearn.impute.MissingIndicator`
188188
Indicator used to add binary indicators for missing values.
189-
``None`` if add_indicator is False.
189+
`None` if `add_indicator=False`.
190190
191191
n_features_in_ : int
192192
Number of features seen during :term:`fit`.
@@ -203,6 +203,11 @@ class SimpleImputer(_BaseImputer):
203203
--------
204204
IterativeImputer : Multivariate imputation of missing values.
205205
206+
Notes
207+
-----
208+
Columns which only contained missing values at :meth:`fit` are discarded
209+
upon :meth:`transform` if strategy is not `"constant"`.
210+
206211
Examples
207212
--------
208213
>>> import numpy as np
@@ -215,12 +220,6 @@ class SimpleImputer(_BaseImputer):
215220
[[ 7. 2. 3. ]
216221
[ 4. 3.5 6. ]
217222
[10. 3.5 9. ]]
218-
219-
Notes
220-
-----
221-
Columns which only contained missing values at :meth:`fit` are discarded
222-
upon :meth:`transform` if strategy is not "constant".
223-
224223
"""
225224

226225
def __init__(
@@ -301,17 +300,21 @@ def _validate_input(self, X, in_fit):
301300
return X
302301

303302
def fit(self, X, y=None):
304-
"""Fit the imputer on X.
303+
"""Fit the imputer on `X`.
305304
306305
Parameters
307306
----------
308307
X : {array-like, sparse matrix}, shape (n_samples, n_features)
309-
Input data, where ``n_samples`` is the number of samples and
310-
``n_features`` is the number of features.
308+
Input data, where `n_samples` is the number of samples and
309+
`n_features` is the number of features.
310+
311+
y : Ignored
312+
Not used, present here for API consistency by convention.
311313
312314
Returns
313315
-------
314-
self : SimpleImputer
316+
self : object
317+
Fitted estimator.
315318
"""
316319
X = self._validate_input(X, in_fit=True)
317320

@@ -449,7 +452,7 @@ def _dense_fit(self, X, strategy, missing_values, fill_value):
449452
return np.full(X.shape[1], fill_value, dtype=X.dtype)
450453

451454
def transform(self, X):
452-
"""Impute all missing values in X.
455+
"""Impute all missing values in `X`.
453456
454457
Parameters
455458
----------
@@ -538,10 +541,10 @@ def inverse_transform(self, X):
538541
This operation can only be performed after :class:`SimpleImputer` is
539542
instantiated with `add_indicator=True`.
540543
541-
Note that ``inverse_transform`` can only invert the transform in
544+
Note that `inverse_transform` can only invert the transform in
542545
features that have binary indicators for missing values. If a feature
543-
has no missing values at ``fit`` time, the feature won't have a binary
544-
indicator, and the imputation done at ``transform`` time won't be
546+
has no missing values at `fit` time, the feature won't have a binary
547+
indicator, and the imputation done at `transform` time won't be
545548
inverted.
546549
547550
.. versionadded:: 0.24
@@ -556,7 +559,7 @@ def inverse_transform(self, X):
556559
Returns
557560
-------
558561
X_original : ndarray of shape (n_samples, n_features)
559-
The original X with missing values as it was prior
562+
The original `X` with missing values as it was prior
560563
to imputation.
561564
"""
562565
check_is_fitted(self)

0 commit comments

Comments
 (0)
0